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

Function test_global_capture_with_live_logging

testing/test_capture.py:1502–1557  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

1500
1501
1502def test_global_capture_with_live_logging(pytester: Pytester) -> None:
1503 # Issue 3819
1504 # capture should work with live cli logging
1505
1506 # Teardown report seems to have the capture for the whole process (setup, capture, teardown)
1507 pytester.makeconftest(
1508 """
1509 def pytest_runtest_logreport(report):
1510 if "test_global" in report.nodeid:
1511 if report.when == "teardown":
1512 with open("caplog", "w") as f:
1513 f.write(report.caplog)
1514 with open("capstdout", "w") as f:
1515 f.write(report.capstdout)
1516 """
1517 )
1518
1519 pytester.makepyfile(
1520 """
1521 import logging
1522 import sys
1523 import pytest
1524
1525 logger = logging.getLogger(__name__)
1526
1527 @pytest.fixture
1528 def fix1():
1529 print("fix setup")
1530 logging.info("fix setup")
1531 yield
1532 logging.info("fix teardown")
1533 print("fix teardown")
1534
1535 def test_global(fix1):
1536 print("begin test")
1537 logging.info("something in test")
1538 print("end test")
1539 """
1540 )
1541 result = pytester.runpytest_subprocess("--log-cli-level=INFO")
1542 assert result.ret == 0
1543
1544 with open("caplog") as f:
1545 caplog = f.read()
1546
1547 assert "fix setup" in caplog
1548 assert "something in test" in caplog
1549 assert "fix teardown" in caplog
1550
1551 with open("capstdout") as f:
1552 capstdout = f.read()
1553
1554 assert "fix setup" in capstdout
1555 assert "begin test" in capstdout
1556 assert "end test" in capstdout
1557 assert "fix teardown" in capstdout
1558
1559

Callers

nothing calls this directly

Calls 4

makeconftestMethod · 0.45
makepyfileMethod · 0.45
runpytest_subprocessMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected