From 708431340884499cf6f6579b3d7ceca47140075c Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 26 Apr 2010 17:56:39 +0200 Subject: [PATCH] factor out session main loop so that distribute testing can make use of it --HG-- branch : trunk --- py/_test/session.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/py/_test/session.py b/py/_test/session.py index f155ffea2..2680aa6fd 100644 --- a/py/_test/session.py +++ b/py/_test/session.py @@ -97,22 +97,26 @@ class Session(object): self.shouldstop = False self.sessionstarts() exitstatus = outcome.EXIT_OK - captured_excinfo = None try: - for item in self.collect(colitems): - if self.shouldstop: - break - if not self.config.option.collectonly: - item.config.hook.pytest_runtest_protocol(item=item) + self._mainloop(colitems) + if self._testsfailed: + exitstatus = outcome.EXIT_TESTSFAILED + self.sessionfinishes(exitstatus=exitstatus) except KeyboardInterrupt: excinfo = py.code.ExceptionInfo() self.config.hook.pytest_keyboard_interrupt(excinfo=excinfo) exitstatus = outcome.EXIT_INTERRUPTED except: excinfo = py.code.ExceptionInfo() - self.config.pluginmanager.notify_exception(captured_excinfo) + self.config.pluginmanager.notify_exception(excinfo) exitstatus = outcome.EXIT_INTERNALERROR - if exitstatus == 0 and self._testsfailed: - exitstatus = outcome.EXIT_TESTSFAILED - self.sessionfinishes(exitstatus=exitstatus) + if exitstatus in (outcome.EXIT_INTERNALERROR, outcome.EXIT_INTERRUPTED): + self.sessionfinishes(exitstatus=exitstatus) return exitstatus + + def _mainloop(self, colitems): + for item in self.collect(colitems): + if self.shouldstop: + break + if not self.config.option.collectonly: + item.config.hook.pytest_runtest_protocol(item=item)