Using capsys in fixtures: AttributeError: 'CaptureFixture' object has no attribute '_capture' #2709
Recently, I had a workshop about parametric tests and fixtures in pytest. As one of the examples I tried to use the
First, working code
def test_print(capsys): print(123, 456, 789) out, err = capsys.readouterr() assert not err.strip() assert '5' in out
$ python -m pytest demo.py ... 1 passed in 0.01 seconds ...
Now I don't like multiple assertions in one test, so let's create a fixture and split it:
import pytest OUT = 0 ERR = 1 @pytest.fixture def captured_print(capsys): print(123, 456, 789) out, err = capsys.readouterr() return out.strip(), err.strip() def test_print_no_stderr(captured_print): assert not captured_print[ERR] def test_print_stdout_contains_5(captured_print): assert '5' in captured_print[OUT]
I think this should work. At least, it feels like a natural way of doing it. But it blows up:
$ python -m pytest demo.py ... AttributeError: 'CaptureFixture' object has no attribute '_capture' ...
$ python --version Python 3.6.2 $ pip freeze py==1.4.34 -e git://github.com/pytest-dev/pytest.git@539523cfee4c49a765569abcf68134b1255eedb5#egg=pytest # also happens on 3.2.1 $ uname Linux $ uname -m x86_64 $ head -n2 /etc/os-release NAME=Fedora VERSION="26 (Twenty Six)"
The text was updated successfully, but these errors were encountered: