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

Function test_do_class_cleanups_on_success

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

Source from the content-addressed store, hash-verified

1318 sys.version_info < (3, 8), reason="Feature introduced in Python 3.8"
1319)
1320def test_do_class_cleanups_on_success(pytester: Pytester) -> None:
1321 testpath = pytester.makepyfile(
1322 """
1323 import unittest
1324 class MyTestCase(unittest.TestCase):
1325 values = []
1326 @classmethod
1327 def setUpClass(cls):
1328 def cleanup():
1329 cls.values.append(1)
1330 cls.addClassCleanup(cleanup)
1331 def test_one(self):
1332 pass
1333 def test_two(self):
1334 pass
1335 def test_cleanup_called_exactly_once():
1336 assert MyTestCase.values == [1]
1337 """
1338 )
1339 reprec = pytester.inline_run(testpath)
1340 passed, skipped, failed = reprec.countoutcomes()
1341 assert failed == 0
1342 assert passed == 3
1343
1344
1345@pytest.mark.skipif(

Callers

nothing calls this directly

Calls 3

countoutcomesMethod · 0.80
makepyfileMethod · 0.45
inline_runMethod · 0.45

Tested by

no test coverage detected