MCPcopy
hub / github.com/pytest-dev/pytest / test_capturing_and_logging_fundamentals

Function test_capturing_and_logging_fundamentals

testing/test_capture.py:1459–1496  ·  view source on GitHub ↗
(pytester: Pytester, method: str)

Source from the content-addressed store, hash-verified

1457 "method", ["SysCapture(2)", "SysCapture(2, tee=True)", "FDCapture(2)"]
1458)
1459def test_capturing_and_logging_fundamentals(pytester: Pytester, method: str) -> None:
1460 # here we check a fundamental feature
1461 p = pytester.makepyfile(
1462 f"""
1463 import sys, os, logging
1464 from _pytest import capture
1465 cap = capture.MultiCapture(
1466 in_=None,
1467 out=None,
1468 err=capture.{method},
1469 )
1470 cap.start_capturing()
1471
1472 logging.warning("hello1")
1473 outerr = cap.readouterr()
1474 print("suspend, captured %s" %(outerr,))
1475 logging.warning("hello2")
1476
1477 cap.pop_outerr_to_orig()
1478 logging.warning("hello3")
1479
1480 outerr = cap.readouterr()
1481 print("suspend2, captured %s" % (outerr,))
1482 """
1483 )
1484 result = pytester.runpython(p)
1485 result.stdout.fnmatch_lines(
1486 """
1487 suspend, captured*hello1*
1488 suspend2, captured*WARNING:root:hello3*
1489 """
1490 )
1491 result.stderr.fnmatch_lines(
1492 """
1493 WARNING:root:hello2
1494 """
1495 )
1496 assert "atexit" not in result.stderr.str()
1497
1498
1499def test_error_attribute_issue555(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 4

fnmatch_linesMethod · 0.80
strMethod · 0.80
makepyfileMethod · 0.45
runpythonMethod · 0.45

Tested by

no test coverage detected