Skip to content

Use of capsys causes log access errors on unit test failures #204

@ca-johnson

Description

@ca-johnson

noticed in #203

When unit tests fail, there is an issue where log file is closed prior to test exiting.

Example error:

Message: 'p4 sync --parallel=threads=0 //...'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "/Users/carl/.pyenv/versions/3.6.0/lib/python3.6/logging/__init__.py", line 989, in emit
    stream.write(msg)
ValueError: I/O operation on closed file.

Repro caused by removing one of the with exception blocks in a unit test (or adding one where an exception is not raised)

I was able to track this down to the use of capsys in test_server_fixture

If we remove such usage, the issue is resolved. However, it is quite convenient to print to stdout the server address.

Suggested solutions:

  • Find a workaround to allow continued use of capsys
  • Remove use of capsys, add to instructions in test_server_fixture to run pytest with a special flag to disable output capturing so you can still see the test server address printed to stdout

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions