-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"ValueError: I/O operation on closed file." with click's CliRunner (capturing) #3344
Comments
GitMate.io thinks possibly related issues are #14 (ValueError: I/O operation on closed file), #2370 (IOError: close() called during concurrent operation on the same file object.), #1873 (with capsys.disabled() causes "I/O operation on closed file"), #3174 (pytest 3.4 breaks test with CherryPy - no attribute 'testscollected' & I/O operation on closed file), and #1585 (Capture is all wrong). |
I've thought that #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. |
Ref: pallets/click#654 |
@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? |
This aimclub/FEDOT#765 was solved this by disabling the logging in stdout. 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:
|
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 #3237).pytest.testing.isolation
: https://github.com/pallets/click/blob/55682f6f5348f5220a557f89c3a796321a52aebf/click/testing.py#L139The text was updated successfully, but these errors were encountered: