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

Method test_add_cleanup

testing/test_config.py:1365–1394  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

1363 assert list(_iter_rewritable_modules(names)) == expected
1364
1365 def test_add_cleanup(self, pytester: Pytester) -> None:
1366 config = Config.fromdictargs({}, [])
1367 config._do_configure()
1368 report = []
1369
1370 class MyError(BaseException):
1371 pass
1372
1373 @config.add_cleanup
1374 def cleanup_last():
1375 report.append("cleanup_last")
1376
1377 @config.add_cleanup
1378 def raise_2():
1379 report.append("raise_2")
1380 raise MyError("raise_2")
1381
1382 @config.add_cleanup
1383 def raise_1():
1384 report.append("raise_1")
1385 raise MyError("raise_1")
1386
1387 @config.add_cleanup
1388 def cleanup_first():
1389 report.append("cleanup_first")
1390
1391 with pytest.raises(MyError, match=r"raise_2"):
1392 config._ensure_unconfigure()
1393
1394 assert report == ["cleanup_first", "raise_1", "raise_2", "cleanup_last"]
1395
1396
1397class TestConfigFromdictargs:

Callers

nothing calls this directly

Calls 3

fromdictargsMethod · 0.80
_do_configureMethod · 0.80
_ensure_unconfigureMethod · 0.80

Tested by

no test coverage detected