diff options
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | testtools/tests/twistedsupport/test_runtest.py | 8 | ||||
-rw-r--r-- | testtools/twistedsupport/_runtest.py | 4 |
3 files changed, 13 insertions, 5 deletions
@@ -16,6 +16,12 @@ Improvements * Fixed example in ``failed`` docstring. (Jonathan Lange, Github #208) +* Rather than explicitly raising a ``KeyboardInterrupt`` if we get no result + from a ``Deferred``, we tell the test result to stop running tests and + report the lack of result as a test error. This ought to make weird + concurrency interaction bugs easier to understand. (Jonathan Lange) + + 2.0.0 ~~~~~ diff --git a/testtools/tests/twistedsupport/test_runtest.py b/testtools/tests/twistedsupport/test_runtest.py index fed5c65..e3c8ab2 100644 --- a/testtools/tests/twistedsupport/test_runtest.py +++ b/testtools/tests/twistedsupport/test_runtest.py @@ -469,8 +469,8 @@ class TestAsynchronousDeferredRunTest(NeedsTwistedTestCase): runner = self.make_runner(test, timeout * 5) result = self.make_result() reactor.callLater(timeout, os.kill, os.getpid(), SIGINT) - self.assertThat(lambda:runner.run(result), - Raises(MatchesException(KeyboardInterrupt))) + runner.run(result) + self.assertThat(result.shouldStop, Equals(True)) @skipIf(os.name != "posix", "Sending SIGINT with os.kill is posix only") def test_fast_keyboard_interrupt_stops_test_run(self): @@ -488,8 +488,8 @@ class TestAsynchronousDeferredRunTest(NeedsTwistedTestCase): runner = self.make_runner(test, timeout * 5) result = self.make_result() reactor.callWhenRunning(os.kill, os.getpid(), SIGINT) - self.assertThat(lambda:runner.run(result), - Raises(MatchesException(KeyboardInterrupt))) + runner.run(result) + self.assertThat(result.shouldStop, Equals(True)) def test_timeout_causes_test_error(self): # If a test times out, it reports itself as having failed with a diff --git a/testtools/twistedsupport/_runtest.py b/testtools/twistedsupport/_runtest.py index 251272e..001ced5 100644 --- a/testtools/twistedsupport/_runtest.py +++ b/testtools/twistedsupport/_runtest.py @@ -395,7 +395,9 @@ class AsynchronousDeferredRunTest(_DeferredRunTest): except NoResultError: # We didn't get a result at all! This could be for any number of # reasons, but most likely someone hit Ctrl-C during the test. - raise KeyboardInterrupt + self._got_user_exception(sys.exc_info()) + self.result.stop() + return False, [] except TimeoutError: # The function took too long to run. self._log_user_exception(TimeoutError(self.case, self._timeout)) |