@@ -948,6 +948,46 @@ def test_one():
948948 assert "!This is stderr!" not in stdout
949949 assert "!This is a warning log msg!" not in stdout
950950
951+ def test_show_capture_with_teardown_logs (self , testdir ):
952+ """Ensure that the capturing of teardown logs honor --show-capture setting"""
953+ testdir .makepyfile (
954+ """
955+ import logging
956+ import sys
957+ import pytest
958+
959+ @pytest.fixture(scope="function", autouse="True")
960+ def hook_each_test(request):
961+ yield
962+ sys.stdout.write("!stdout!")
963+ sys.stderr.write("!stderr!")
964+ logging.warning("!log!")
965+
966+ def test_func():
967+ assert False
968+ """
969+ )
970+
971+ result = testdir .runpytest ("--show-capture=stdout" , "--tb=short" ).stdout .str ()
972+ assert "!stdout!" in result
973+ assert "!stderr!" not in result
974+ assert "!log!" not in result
975+
976+ result = testdir .runpytest ("--show-capture=stderr" , "--tb=short" ).stdout .str ()
977+ assert "!stdout!" not in result
978+ assert "!stderr!" in result
979+ assert "!log!" not in result
980+
981+ result = testdir .runpytest ("--show-capture=log" , "--tb=short" ).stdout .str ()
982+ assert "!stdout!" not in result
983+ assert "!stderr!" not in result
984+ assert "!log!" in result
985+
986+ result = testdir .runpytest ("--show-capture=no" , "--tb=short" ).stdout .str ()
987+ assert "!stdout!" not in result
988+ assert "!stderr!" not in result
989+ assert "!log!" not in result
990+
951991
952992@pytest .mark .xfail ("not hasattr(os, 'dup')" )
953993def test_fdopen_kept_alive_issue124 (testdir ):
0 commit comments