Fixed test.

This commit is contained in:
victor 2018-08-19 14:29:57 +02:00
parent 2255892d65
commit 9e382e8d29
1 changed files with 24 additions and 14 deletions

View File

@ -1396,32 +1396,29 @@ def test_capture_with_live_logging(testdir):
def pytest_runtest_logreport(report): def pytest_runtest_logreport(report):
if "test_global" in report.nodeid: if "test_global" in report.nodeid:
if report.when == "teardown": if report.when == "teardown":
assert "fix setup" in report.caplog with open("caplog", "w") as f:
assert "something in test" in report.caplog f.write(report.caplog)
assert "fix teardown" in report.caplog with open("capstdout", "w") as f:
f.write(report.capstdout)
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( testdir.makepyfile(
""" """
import logging import logging
import sys import sys
import pytest
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@pytest.fixture @pytest.fixture
def fix1(): def fix1():
print("fix setup") print("fix setup")
logging("fix setup") logging.info("fix setup")
yield yield
logging("fix teardown") logging.info("fix teardown")
print("fix teardown") print("fix teardown")
def test_global(): def test_global(fix1):
print("begin test") print("begin test")
logging.info("something in test") logging.info("something in test")
print("end test") print("end test")
@ -1434,9 +1431,7 @@ def test_capture_with_live_logging(testdir):
assert captured.err == "world\\n" assert captured.err == "world\\n"
logging.info("something") logging.info("something")
print("next") print("next")
logging.info("something") logging.info("something")
captured = capsys.readouterr() captured = capsys.readouterr()
@ -1445,3 +1440,18 @@ def test_capture_with_live_logging(testdir):
) )
result = testdir.runpytest_subprocess("--log-cli-level=INFO") result = testdir.runpytest_subprocess("--log-cli-level=INFO")
assert result.ret == 0 assert result.ret == 0
with open("caplog", "r") as f:
caplog = f.read()
assert "fix setup" in caplog
assert "something in test" in caplog
assert "fix teardown" in caplog
with open("capstdout", "r") as f:
capstdout = f.read()
assert "fix setup" in capstdout
assert "begin test" in capstdout
assert "end test" in capstdout
assert "fix teardown" in capstdout