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

Function test_change_level_undo

testing/logging/test_fixture.py:31–54  ·  view source on GitHub ↗

Ensure that 'set_level' is undone after the end of the test. Tests the logging output themselves (affacted both by logger and handler levels).

(pytester: Pytester)

Source from the content-addressed store, hash-verified

29
30
31def test_change_level_undo(pytester: Pytester) -> None:
32 """Ensure that 'set_level' is undone after the end of the test.
33
34 Tests the logging output themselves (affacted both by logger and handler levels).
35 """
36 pytester.makepyfile(
37 """
38 import logging
39
40 def test1(caplog):
41 caplog.set_level(logging.INFO)
42 # using + operator here so fnmatch_lines doesn't match the code in the traceback
43 logging.info('log from ' + 'test1')
44 assert 0
45
46 def test2(caplog):
47 # using + operator here so fnmatch_lines doesn't match the code in the traceback
48 logging.info('log from ' + 'test2')
49 assert 0
50 """
51 )
52 result = pytester.runpytest()
53 result.stdout.fnmatch_lines(["*log from test1*", "*2 failed in *"])
54 result.stdout.no_fnmatch_line("*log from test2*")
55
56
57def test_change_level_undos_handler_level(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 4

fnmatch_linesMethod · 0.80
no_fnmatch_lineMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected