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

Function test_setup_teardown_warnings

testing/test_warnings.py:59–85  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

57
58@pytest.mark.filterwarnings("always::UserWarning")
59def test_setup_teardown_warnings(pytester: Pytester) -> None:
60 pytester.makepyfile(
61 """
62 import warnings
63 import pytest
64
65 @pytest.fixture
66 def fix():
67 warnings.warn(UserWarning("warning during setup"))
68 yield
69 warnings.warn(UserWarning("warning during teardown"))
70
71 def test_func(fix):
72 pass
73 """
74 )
75 result = pytester.runpytest()
76 result.stdout.fnmatch_lines(
77 [
78 "*== %s ==*" % WARNINGS_SUMMARY_HEADER,
79 "*test_setup_teardown_warnings.py:6: UserWarning: warning during setup",
80 '*warnings.warn(UserWarning("warning during setup"))',
81 "*test_setup_teardown_warnings.py:8: UserWarning: warning during teardown",
82 '*warnings.warn(UserWarning("warning during teardown"))',
83 "* 1 passed, 2 warnings*",
84 ]
85 )
86
87
88@pytest.mark.parametrize("method", ["cmdline", "ini"])

Callers

nothing calls this directly

Calls 3

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected