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

Function test_module_and_function_setup

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

Source from the content-addressed store, hash-verified

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