summaryrefslogtreecommitdiff
path: root/testing/test_capture.py
diff options
context:
space:
mode:
authorvictor <victor.maryama@typhoon-hil.com>2018-08-19 13:44:12 +0200
committervictor <victor.maryama@typhoon-hil.com>2018-08-19 13:44:12 +0200
commit2255892d65810cc4db2b82e2621ed313a0c47f7f (patch)
treeb4195af5b3a39d5d68e5f2a23fb7147b9cc268f6 /testing/test_capture.py
parent7d9b198f734f7d1968c88476545da29fb90c1040 (diff)
downloadpytest-2255892d65810cc4db2b82e2621ed313a0c47f7f.tar.gz
Improved test to cover more cases.
Diffstat (limited to 'testing/test_capture.py')
-rw-r--r--testing/test_capture.py37
1 files changed, 33 insertions, 4 deletions
diff --git a/testing/test_capture.py b/testing/test_capture.py
index 782971af0..e47689c9c 100644
--- a/testing/test_capture.py
+++ b/testing/test_capture.py
@@ -1387,17 +1387,46 @@ def test_pickling_and_unpickling_encoded_file():
pickle.loads(ef_as_str)
-def test_capsys_with_cli_logging(testdir):
+def test_capture_with_live_logging(testdir):
# Issue 3819
- # capsys should work with real-time cli logging
+ # capture should work with live cli logging
+
+ # Teardown report seems to have the capture for the whole process (setup, capture, teardown)
+ testdir.makeconftest("""
+ def pytest_runtest_logreport(report):
+ if "test_global" in report.nodeid:
+ if report.when == "teardown":
+ assert "fix setup" in report.caplog
+ assert "something in test" in report.caplog
+ assert "fix teardown" in report.caplog
+
+ assert "fix setup" in report.capstdout
+ assert "begin test" in report.capstdout
+ assert "end test" in report.capstdout
+ assert "fix teardown" in report.capstdout
+ """)
+
testdir.makepyfile(
"""
import logging
import sys
logger = logging.getLogger(__name__)
-
- def test_myoutput(capsys): # or use "capfd" for fd-level
+
+ @pytest.fixture
+ def fix1():
+ print("fix setup")
+ logging("fix setup")
+ yield
+ logging("fix teardown")
+ print("fix teardown")
+
+ def test_global():
+ print("begin test")
+ logging.info("something in test")
+ print("end test")
+
+ def test_capsys(capsys): # or use "capfd" for fd-level
print("hello")
sys.stderr.write("world\\n")
captured = capsys.readouterr()