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

Method test_show_capture

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

Source from the content-addressed store, hash-verified

1653 result.stdout.fnmatch_lines(["*hello: 42*", "line1", str(pytester.path)])
1654
1655 def test_show_capture(self, pytester: Pytester) -> None:
1656 pytester.makepyfile(
1657 """
1658 import sys
1659 import logging
1660 def test_one():
1661 sys.stdout.write('!This is stdout!')
1662 sys.stderr.write('!This is stderr!')
1663 logging.warning('!This is a warning log msg!')
1664 assert False, 'Something failed'
1665 """
1666 )
1667
1668 result = pytester.runpytest("--tb=short")
1669 result.stdout.fnmatch_lines(
1670 [
1671 "!This is stdout!",
1672 "!This is stderr!",
1673 "*WARNING*!This is a warning log msg!",
1674 ]
1675 )
1676
1677 result = pytester.runpytest("--show-capture=all", "--tb=short")
1678 result.stdout.fnmatch_lines(
1679 [
1680 "!This is stdout!",
1681 "!This is stderr!",
1682 "*WARNING*!This is a warning log msg!",
1683 ]
1684 )
1685
1686 stdout = pytester.runpytest("--show-capture=stdout", "--tb=short").stdout.str()
1687 assert "!This is stderr!" not in stdout
1688 assert "!This is stdout!" in stdout
1689 assert "!This is a warning log msg!" not in stdout
1690
1691 stdout = pytester.runpytest("--show-capture=stderr", "--tb=short").stdout.str()
1692 assert "!This is stdout!" not in stdout
1693 assert "!This is stderr!" in stdout
1694 assert "!This is a warning log msg!" not in stdout
1695
1696 stdout = pytester.runpytest("--show-capture=log", "--tb=short").stdout.str()
1697 assert "!This is stdout!" not in stdout
1698 assert "!This is stderr!" not in stdout
1699 assert "!This is a warning log msg!" in stdout
1700
1701 stdout = pytester.runpytest("--show-capture=no", "--tb=short").stdout.str()
1702 assert "!This is stdout!" not in stdout
1703 assert "!This is stderr!" not in stdout
1704 assert "!This is a warning log msg!" not in stdout
1705
1706 def test_show_capture_with_teardown_logs(self, pytester: Pytester) -> None:
1707 """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