Bug: ClearML and `pytest.capsys`
See original GitHub issuePytest has capsys
(link) option for capturing stdout
and making it available in the tests.
Unfortunately, this breaks when used with ClearML’s automatic logging.
Stacktrace:
Traceback (most recent call last):
File "/usr/local/bin/pytest", line 8, in <module>
sys.exit(console_main())
File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 187, in console_main
code = main()
File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 164, in main
ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
File "/usr/local/lib/python3.8/dist-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/usr/local/lib/python3.8/dist-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 60, in _multicall
return outcome.get_result()
File "/usr/local/lib/python3.8/dist-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/usr/local/lib/python3.8/dist-packages/_pytest/main.py", line 315, in pytest_cmdline_main
return wrap_session(config, _main)
File "/usr/local/lib/python3.8/dist-packages/_pytest/main.py", line 310, in wrap_session
config._ensure_unconfigure()
File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 1004, in _ensure_unconfigure
fin()
File "/usr/local/lib/python3.8/dist-packages/_pytest/capture.py", line 666, in stop_global_capturing
self._global_capturing.pop_outerr_to_orig()
File "/usr/local/lib/python3.8/dist-packages/_pytest/capture.py", line 552, in pop_outerr_to_orig
out, err = self.readouterr()
File "/usr/local/lib/python3.8/dist-packages/_pytest/capture.py", line 597, in readouterr
err = self.err.snap() if self.err else ""
File "/usr/local/lib/python3.8/dist-packages/_pytest/capture.py", line 314, in snap
res = self.tmpfile.getvalue()
File "/usr/local/lib/python3.8/dist-packages/_pytest/capture.py", line 175, in getvalue
return self.buffer.getvalue().decode("UTF-8")
ValueError: I/O operation on closed file.
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
pytest with capsys causes random test failures #2195 - GitHub
Problem: running tests with output capturing causes random failures catboost version:1.1. Operating System: linux ...
Read more >pytest capsys: checking output AND getting it reported?
You're seeing the correct behaviour, when using capsys.readouterr() you're consuming the captured output. Hence any output to stdout and ...
Read more >pytest's capsys.disabled() not working as expected - splunktool
So, I found a hint by a pytest dev, anycodings_pytest based on which I basically do what the anycodings_pytest capsys.disable() function ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey I must confess that I am not familiar with pytest - could you give me some more precisions about :
We had an issue concerning Pycharm testrunner (here and here).The issue is that pycharm builds a wrapping file that contains the script to test - and that wrapper is local file, that clearml tries to pull from a repo… Do you think it could be a similar behavior here ?
Thanks
I just realized that the error is that
readlogerr
(doesn’t exist). It should bereadouterr
🤦 .The clearml error happened while handling ☝️ error, so I guess this issue can be closed.
I’m sorry for the time but thanks for leading me to the actual problem. 😃