pytest capsys not caputuring output
See original GitHub issueHey,
according to the docs I was expecting the default logger to write to stderr:
you can use the Logger right after import as it comes pre-configured (logs are emitted to sys.stderr by default)
So I was running this minimal example with pytest and was expecting it to work:
from loguru import logger
def test_logger(capsys):
logger.error("Some Error")
out, err = capsys.readouterr()
assert "Some Error" in err
However it fails. When I add an explicit Handler that writed to stderr, it works. Why does the default handler not work?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
stdout not captured by pytest capsys when using fixture
Here, capsys does not capture sys.stderr properly. If I move from sys import stdout and args.out = stdout directly into the test function, ......
Read more >stdout capture (capsys) does not seem to work with real-time ...
Running with pytest --log-cli-level=INFO makes the test fail as the captured.out variable comes empty. pip list of the virtual environment you ...
Read more >How to capture stdout/stderr output — pytest documentation
tee-sys capturing: Python writes to sys.stdout and sys.stderr will be captured, ... output is captured") with capsys.disabled(): print("output not captured, ...
Read more >Using pytest, sometimes does not capture stderr
Using pytest, sometimes does not capture stderr ... capsys = <_pytest.capture. ... 1) The final line of the pytest failure output seems to...
Read more >Pytest capsys - Waylon Walker
capsys is a builtin pytest fixture that can be passed into any test to capture stdin/stdout. For a more comprehensive description check out ......
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 FreeTop 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
Top GitHub Comments
Hi.
This is not working out of the box with
capsys
due to Pytest internals which replacesys.stderr
with their own special object. Consequently, iflogger.add()
was called prior to the running the test, the Loguru’s handler is lost.Sure, will do. Thanks