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

Function test_capturing_and_logging_fundamentals

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

Source from the content-addressed store, hash-verified

1376 "method", ["SysCapture(2)", "SysCapture(2, tee=True)", "FDCapture(2)"]
1377)
1378def test_capturing_and_logging_fundamentals(pytester: Pytester, method: str) -> None:
1379 # here we check a fundamental feature
1380 p = pytester.makepyfile(
1381 """
1382 import sys, os, logging
1383 from _pytest import capture
1384 cap = capture.MultiCapture(
1385 in_=None,
1386 out=None,
1387 err=capture.%s,
1388 )
1389 cap.start_capturing()
1390
1391 logging.warning("hello1")
1392 outerr = cap.readouterr()
1393 print("suspend, captured %%s" %%(outerr,))
1394 logging.warning("hello2")
1395
1396 cap.pop_outerr_to_orig()
1397 logging.warning("hello3")
1398
1399 outerr = cap.readouterr()
1400 print("suspend2, captured %%s" %% (outerr,))
1401 """
1402 % (method,)
1403 )
1404 result = pytester.runpython(p)
1405 result.stdout.fnmatch_lines(
1406 """
1407 suspend, captured*hello1*
1408 suspend2, captured*WARNING:root:hello3*
1409 """
1410 )
1411 result.stderr.fnmatch_lines(
1412 """
1413 WARNING:root:hello2
1414 """
1415 )
1416 assert "atexit" not in result.stderr.str()
1417
1418
1419def 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