Closed blueyed closed 4 years ago
GitMate.io thinks possibly related issues are https://github.com/pytest-dev/pytest/issues/14 (ValueError: I/O operation on closed file), https://github.com/pytest-dev/pytest/issues/2370 (IOError: close() called during concurrent operation on the same file object.), https://github.com/pytest-dev/pytest/issues/1873 (with capsys.disabled() causes "I/O operation on closed file"), https://github.com/pytest-dev/pytest/issues/3174 (pytest 3.4 breaks test with CherryPy - no attribute 'testscollected' & I/O operation on closed file), and https://github.com/pytest-dev/pytest/issues/1585 (Capture is all wrong).
I've thought that https://github.com/pytest-dev/pytest/pull/2619 might have helped here, but it does not - but without having investigated much it might go in the right direction.
It looks a bit like pytest should maybe restore / handle the changed output stream(s) from the outer context manager, but uses the one(s) from before the test started.
@blueyed why did you close this?
@blueyed how did you resolve this issue? I am facing the same problem.
@blueyed Was this resolved? Why is this closed?
@blueyed Was this resolved? Why is this closed?
This nccr-itmo/FEDOT#765 was solved this by disabling the logging in stdout. the issue is related to how logging is handled between click & pytest
a potential resolution to pytest cli is to add the "--capture=no" or "-s" (note: -s is a shortcut) parameter which will disable log capturing.
I followed suggestion to remove CliRunner. Seems that it works this way (link to docs):
with function_under_test.make_context('function_under_test', ['arg1', 'arg2']) as ctx:
result = function_under_test.invoke(ctx)
@Solvero result is allways None for you to ?
does someone found a way to fix the issue? or to overcome it?
@snirbenyosef I've just checked. I have correct value returned (in my case its integer).
Please double check that you return value in 'function_under_test'.
@Solvero I meant I want the stdout and the exit_code, is it possible?
For that I would use subprocess instead:
resp = subprocess.check_output(...)
assert resp.returncode == 0
assert resp.stdout ....
With click's CliRunner I've noticed that it throws a ValueError when pytest's pdb gets used in the
CliRunner.isolation
context:test_pytest_capture.py
:Test run:
When using
-s
bdb.BdbQuit
is raised:The ValueError comes from
out.getvalue
really, the location is off due to thepdb.set_trace
(see https://github.com/pytest-dev/pytest/issues/3237).pytest.testing.isolation
: https://github.com/pallets/click/blob/55682f6f5348f5220a557f89c3a796321a52aebf/click/testing.py#L139