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

Method test_show_capture

testing/test_terminal.py:1471–1520  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

1469 result.stdout.fnmatch_lines(["*hello: 42*", "line1", str(pytester.path)])
1470
1471 def test_show_capture(self, pytester: Pytester) -> None:
1472 pytester.makepyfile(
1473 """
1474 import sys
1475 import logging
1476 def test_one():
1477 sys.stdout.write('!This is stdout!')
1478 sys.stderr.write('!This is stderr!')
1479 logging.warning('!This is a warning log msg!')
1480 assert False, 'Something failed'
1481 """
1482 )
1483
1484 result = pytester.runpytest("--tb=short")
1485 result.stdout.fnmatch_lines(
1486 [
1487 "!This is stdout!",
1488 "!This is stderr!",
1489 "*WARNING*!This is a warning log msg!",
1490 ]
1491 )
1492
1493 result = pytester.runpytest("--show-capture=all", "--tb=short")
1494 result.stdout.fnmatch_lines(
1495 [
1496 "!This is stdout!",
1497 "!This is stderr!",
1498 "*WARNING*!This is a warning log msg!",
1499 ]
1500 )
1501
1502 stdout = pytester.runpytest("--show-capture=stdout", "--tb=short").stdout.str()
1503 assert "!This is stderr!" not in stdout
1504 assert "!This is stdout!" in stdout
1505 assert "!This is a warning log msg!" not in stdout
1506
1507 stdout = pytester.runpytest("--show-capture=stderr", "--tb=short").stdout.str()
1508 assert "!This is stdout!" not in stdout
1509 assert "!This is stderr!" in stdout
1510 assert "!This is a warning log msg!" not in stdout
1511
1512 stdout = pytester.runpytest("--show-capture=log", "--tb=short").stdout.str()
1513 assert "!This is stdout!" not in stdout
1514 assert "!This is stderr!" not in stdout
1515 assert "!This is a warning log msg!" in stdout
1516
1517 stdout = pytester.runpytest("--show-capture=no", "--tb=short").stdout.str()
1518 assert "!This is stdout!" not in stdout
1519 assert "!This is stderr!" not in stdout
1520 assert "!This is a warning log msg!" not in stdout
1521
1522 def test_show_capture_with_teardown_logs(self, pytester: Pytester) -> None:
1523 """Ensure that the capturing of teardown logs honor --show-capture setting"""

Callers

nothing calls this directly

Calls 4

fnmatch_linesMethod · 0.80
strMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected