MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_disabled_capture_fixture

Method test_disabled_capture_fixture

testing/test_capture.py:622–648  ·  view source on GitHub ↗
(
        self, pytester: Pytester, fixture: str, no_capture: bool
    )

Source from the content-addressed store, hash-verified

620 @pytest.mark.parametrize("fixture", ["capsys", "capfd"])
621 @pytest.mark.parametrize("no_capture", [True, False])
622 def test_disabled_capture_fixture(
623 self, pytester: Pytester, fixture: str, no_capture: bool
624 ) -> None:
625 pytester.makepyfile(
626 """\
627 def test_disabled({fixture}):
628 print('captured before')
629 with {fixture}.disabled():
630 print('while capture is disabled')
631 print('captured after')
632 assert {fixture}.readouterr() == ('captured before\\ncaptured after\\n', '')
633
634 def test_normal():
635 print('test_normal executed')
636 """.format(
637 fixture=fixture
638 )
639 )
640 args = ("-s",) if no_capture else ()
641 result = pytester.runpytest_subprocess(*args)
642 result.stdout.fnmatch_lines(["*while capture is disabled*", "*= 2 passed in *"])
643 result.stdout.no_fnmatch_line("*captured before*")
644 result.stdout.no_fnmatch_line("*captured after*")
645 if no_capture:
646 assert "test_normal executed" in result.stdout.str()
647 else:
648 result.stdout.no_fnmatch_line("*test_normal executed*")
649
650 def test_disabled_capture_fixture_twice(self, pytester: Pytester) -> None:
651 """Test that an inner disabled() exit doesn't undo an outer disabled().

Callers

nothing calls this directly

Calls 6

fnmatch_linesMethod · 0.80
no_fnmatch_lineMethod · 0.80
strMethod · 0.80
makepyfileMethod · 0.45
formatMethod · 0.45
runpytest_subprocessMethod · 0.45

Tested by

no test coverage detected