Skip to content

Commit 0dd1c8b

Browse files
committed
Add test to ensure capsys and capfd error out when using "getfixturevalue" inside a test
1 parent 0ca0696 commit 0dd1c8b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

testing/test_capture.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,25 @@ def test_two(capfd, capsys):
421421
"*capsys*capfd*same*time*",
422422
"*2 error*"])
423423

424+
def test_capturing_getfixturevalue(self, testdir):
425+
"""Test that asking for "capfd" and "capsys" using request.getfixturevalue
426+
in the same test is an error.
427+
"""
428+
testdir.makepyfile("""
429+
def test_one(capsys, request):
430+
request.getfixturevalue("capfd")
431+
def test_two(capfd, request):
432+
request.getfixturevalue("capsys")
433+
""")
434+
result = testdir.runpytest()
435+
result.stdout.fnmatch_lines([
436+
"*test_one*",
437+
"*capsys*capfd*same*time*",
438+
"*test_two*",
439+
"*capsys*capfd*same*time*",
440+
"*2 failed in*",
441+
])
442+
424443
@pytest.mark.parametrize("method", ["sys", "fd"])
425444
def test_capture_is_represented_on_failure_issue128(self, testdir, method):
426445
p = testdir.makepyfile("""

0 commit comments

Comments
 (0)