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

Function test_module_and_function_setup

testing/test_runner_xunit.py:10–40  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

8
9
10def test_module_and_function_setup(pytester: Pytester) -> None:
11 reprec = pytester.inline_runsource(
12 """
13 modlevel = []
14 def setup_module(module):
15 assert not modlevel
16 module.modlevel.append(42)
17
18 def teardown_module(module):
19 modlevel.pop()
20
21 def setup_function(function):
22 function.answer = 17
23
24 def teardown_function(function):
25 del function.answer
26
27 def test_modlevel():
28 assert modlevel[0] == 42
29 assert test_modlevel.answer == 17
30
31 class TestFromClass(object):
32 def test_module(self):
33 assert modlevel[0] == 42
34 assert not hasattr(test_modlevel, 'answer')
35 """
36 )
37 rep = reprec.matchreport("test_modlevel")
38 assert rep.passed
39 rep = reprec.matchreport("test_module")
40 assert rep.passed
41
42
43def test_module_setup_failure_no_teardown(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 2

matchreportMethod · 0.80
inline_runsourceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…