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

Function test_setup

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

Source from the content-addressed store, hash-verified

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