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

Function test_messages_logged

testing/logging/test_reporting.py:33–52  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

31
32
33def test_messages_logged(pytester: Pytester) -> None:
34 pytester.makepyfile(
35 """
36 import sys
37 import logging
38
39 logger = logging.getLogger(__name__)
40
41 def test_foo():
42 sys.stdout.write('text going to stdout')
43 sys.stderr.write('text going to stderr')
44 logger.info('text going to logger')
45 assert False
46 """
47 )
48 result = pytester.runpytest("--log-level=INFO")
49 assert result.ret == 1
50 result.stdout.fnmatch_lines(["*- Captured *log call -*", "*text going to logger*"])
51 result.stdout.fnmatch_lines(["*- Captured stdout call -*", "text going to stdout"])
52 result.stdout.fnmatch_lines(["*- Captured stderr call -*", "text going to stderr"])
53
54
55def test_root_logger_affected(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 3

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected