pytest-dev / pytest-dev/pytest
Output appears in "Captured stderr call" but is unavailable in capsys or capfd
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Environment
Pytest version: 5.2.1
Operating system: Kubuntu 18.04.3 LTS
Pip list:
Package Version
------------------ -------
atomicwrites 1.3.0
attrs 19.3.0
importlib-metadata 0.23
more-itertools 7.2.0
packaging 19.2
pip 19.3.1
pluggy 0.13.0
py 1.8.0
pyparsing 2.4.2
pytest 5.2.1
setuptools 41.4.0
six 1.12.0
wcwidth 0.1.7
wheel 0.33.6
zipp 0.6.0
Description
It seems that output can appear in "Captured stderr call" but be unavailable to capsys or capfd, which can be a bug? It's definitely weird.
I came accross this issue while trying to test my logging setup. This is a minimal example I came up with (available at https://github.com/butla/experiments/tree/master/pytest_capture_log_error):
# a_file.py
import logging
logging.basicConfig(level=logging.INFO)
LOG_MESSAGE = "the message we'll look for in the test"
_log = logging.getLogger(__name__)
def bla():
_log.info(LOG_MESSAGE)
return 5
# test_file.py
import a_file
def test_a(capsys):
assert a_file.bla() == 5
assert a_file.LOG_MESSAGE in capsys.readouterr().err
The test fails and it shows
------------------------------------------ Captured stderr call ------------------------------------------
INFO:a_file:the message we'll look for in the test
but both capsys and capfd show out and err to be empty.
I would use caplog, but the messages I get from it don't conform to the log configuration that I have set up in my original app, so I decided to just use stderr.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with the a_file.py and test_file.py example, then inspect pytest's capsys, capfd, and logging capture behavior. Compare the empty capsys/capfd results with the displayed Captured stderr call output; done means the behavior is explained and covered by a regression test or the issue is confirmed as expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100