From 42a651c6e23b4156c5bc37208d97d0788e09edf7 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 23 Dec 2019 15:41:36 -0500 Subject: A way to artificially crash coverage, for testing. --- tests/test_api.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/test_api.py') diff --git a/tests/test_api.py b/tests/test_api.py index 30a90c3c..369324f7 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -676,6 +676,21 @@ class ApiTest(CoverageTest): with self.assertRaisesRegex(CoverageException, msg): cov.switch_context("test3") + def test_config_crash(self): + # The internal '[run] _crash' setting can be used to artificially raise + # exceptions from inside Coverage. + cov = coverage.Coverage() + cov.set_option("run:_crash", "test_config_crash") + with self.assertRaisesRegex(Exception, "Crashing because called by test_config_crash"): + cov.start() + + def test_config_crash_no_crash(self): + # '[run] _crash' really checks the call stack. + cov = coverage.Coverage() + cov.set_option("run:_crash", "not_my_caller") + cov.start() + cov.stop() + class CurrentInstanceTest(CoverageTest): """Tests of Coverage.current().""" -- cgit v1.2.1