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

Function test_setup

testing/test_unittest.py:66–86  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

64
65
66def test_setup(pytester: Pytester) -> None:
67 testpath = pytester.makepyfile(
68 """
69 import unittest
70 class MyTestCase(unittest.TestCase):
71 def setUp(self):
72 self.foo = 1
73 def setup_method(self, method):
74 self.foo2 = 1
75 def test_both(self):
76 self.assertEqual(1, self.foo)
77 assert self.foo2 == 1
78 def teardown_method(self, method):
79 assert 0, "42"
80
81 """
82 )
83 reprec = pytester.inline_run("-s", testpath)
84 assert reprec.matchreport("test_both", when="call").passed
85 rep = reprec.matchreport("test_both", when="teardown")
86 assert rep.failed and "42" in str(rep.longrepr)
87
88
89def test_setUpModule(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 3

matchreportMethod · 0.80
makepyfileMethod · 0.45
inline_runMethod · 0.45

Tested by

no test coverage detected