Improved test to cover more cases.
This commit is contained in:
parent
7d9b198f73
commit
2255892d65
|
@ -1387,9 +1387,25 @@ 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
|
||||
|
@ -1397,7 +1413,20 @@ def test_capsys_with_cli_logging(testdir):
|
|||
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue