capfd not working in 3.3.1
See original GitHub issueFixtures that use capfd don’t seem to work in version 3.3.1 running on Ubuntu 14.04 LTS with anaconda 3.6.3
import sys
@pytest.fixture()
def fix(capfd):
yield None
out, err = capfd.readouterr()
stdout_filename = "/tmp/stdout"
stderr_filename = "/tmp/stderr"
mode = 'w'
with open(stdout_filename, mode) as stdout:
stdout.write(out)
with open(stderr_filename, mode) as stderr:
stderr.write(err)
def test_a(fix):
print("lolcatz")
print("this is a test")
sys.stderr.write("err")
The stdout and stderr files end up empty after running that test. Using this set of pytest dependencies
certifi (2017.11.5)
pip (9.0.1)
pluggy (0.6.0)
py (1.5.2)
pytest (3.3.1)
setuptools (38.2.4)
six (1.11.0)
wheel (0.30.0)
Steps of replication are
- Create the above test
- Run pytest on it.
- cat /tmp/std* (they will be empty)
- Downgrade pytest ( pip install autohil==3.2.5 )
- Run the test again
- cat /tmp/std*
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
How to use logging, pytest fixture and capsys? - Stack Overflow
Reverse logger, capsys , make logger request the capsys fixture and use capfd do not change anything. I tried pytest-catchlog plugin and it ......
Read more >pytest Documentation - Read the Docs
an empty directory as the current working directory but otherwise do not care for the concrete directory. Here is how.
Read more >Changelog — pytest documentation
This solves some issues with tests that involve pytest environment variables. ... CaptureFixture[str] for the capfd and capsys fixtures. pytest.
Read more >python-pytest-3.3.2-bp150.2.4 - SUSE Package Hub -
(#2644) - Fix error on Windows and Python 3.6+ when sys.stdout has been replaced with a stream-like object which does not implement the...
Read more >pytest API Manual - Hubwiz.com
... Some Issues and Questions · pytest fixtures: explicit, modular, scalable · pytest-2.3: ... pytest 3.3.2 (2017-12-25) · pytest 3.3.1 (2017-12-05) ...
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
@nicoddemus I found the error.
https://github.com/nicoddemus/pytest/commit/9919269ed048b6e9147ee3301532e3591b9a112b#diff-d8641d58661f0fa63a36c6f6e85715d9R163
It’s a 1 liner. Remove activate_fixture(item) from teardown. It causes a double start which effectively clears the results before they show up in the fixture.
@AlexanderTyrrell #3830 will also fix that
AttributeError: 'tuple' object has no attribute 'out'
error. 👍