question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: ClearML and `pytest.capsys`

See original GitHub issue

Pytest 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:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
DavidNativcommented, Jun 22, 2022

Hey I must confess that I am not familiar with pytest - could you give me some more precisions about :

  • how to run it (for ex. the kind of stuffs into <folder-with-tests>)
  • what you intend to do using that package

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

0reactions
alekpiklcommented, Jun 29, 2022

I just realized that the error is that readlogerr (doesn’t exist). It should be readouterr 🤦 .

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. 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found