Properly wait for workers when test run terminates early (#963)
Currently, a reason to terminate early (e.g. test failure with --exitfail option set) causes DSession to immediately raise an Interrupt exception. Subsequent reports generated by the workers, during the shutdown phase, are discarded. One consequence is that, for the failing test, teardown and testfinish are ignored, which prevents corresponding hooks pytest_runtest_logreport and pytest_runtest_logfinish being executed for the failing test (this problem covered in #54). The reporting of tests executing in other workers is also left in an indeterminate state. This can affect other plugin code. This is a relatively simple fix, which appears to have minimal and, I think, acceptable impact on text execution behaviour. The observable differences are differences in what is reported about a test run. For example, when running, for example with the '-x/--exitfail' option, it is possible that more than a single test failure is reported. This is because more than one test did fail before the test run was completely stopped. The reporting is absolutely correct; and complete. Prior to this change, only a single failure would have been reported, but because of incomplete and arguably incorrect reporting.
This commit is contained in:
@@ -118,11 +118,14 @@ class DSession:
|
||||
assert self.sched is not None
|
||||
|
||||
self.shouldstop = False
|
||||
pending_exception = None
|
||||
while not self.session_finished:
|
||||
self.loop_once()
|
||||
if self.shouldstop:
|
||||
self.triggershutdown()
|
||||
raise Interrupted(str(self.shouldstop))
|
||||
pending_exception = Interrupted(str(self.shouldstop))
|
||||
if pending_exception:
|
||||
raise pending_exception
|
||||
return True
|
||||
|
||||
def loop_once(self):
|
||||
@@ -351,14 +354,19 @@ class DSession:
|
||||
def _handlefailures(self, rep):
|
||||
if rep.failed:
|
||||
self.countfailures += 1
|
||||
if self.maxfail and self.countfailures >= self.maxfail:
|
||||
if (
|
||||
self.maxfail
|
||||
and self.countfailures >= self.maxfail
|
||||
and not self.shouldstop
|
||||
):
|
||||
self.shouldstop = f"stopping after {self.countfailures} failures"
|
||||
|
||||
def triggershutdown(self):
|
||||
self.log("triggering shutdown")
|
||||
self.shuttingdown = True
|
||||
for node in self.sched.nodes:
|
||||
node.shutdown()
|
||||
if not self.shuttingdown:
|
||||
self.log("triggering shutdown")
|
||||
self.shuttingdown = True
|
||||
for node in self.sched.nodes:
|
||||
node.shutdown()
|
||||
|
||||
def handle_crashitem(self, nodeid, worker):
|
||||
# XXX get more reporting info by recording pytest_runtest_logstart?
|
||||
|
||||
Reference in New Issue
Block a user