-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xdist bails out too soon when using --exitfirst #54
Comments
it makes sense, but the direction is not clear at first glance we do have a problem of spaghetti state machines in general (state machines that exist via code that randomly interacts) and this issue seems to be yet another manifestation of exiting one at a non-exitable state |
I experimented a bit and this change seems to work (whether it is appropriate, I'm not sure): diff --git a/xdist/dsession.py b/xdist/dsession.py
index fa66f1d..cfc0335 100644
--- a/xdist/dsession.py
+++ b/xdist/dsession.py
@@ -515,8 +515,23 @@ class DSession:
nm = getattr(self, 'nodemanager', None) # if not fully initialized
if nm is not None:
nm.teardown_nodes()
+ self._drain_queue()
+
self._session = None
+ def _drain_queue(self):
+ while 1:
+ try:
+ eventcall = self.queue.get_nowait()
+ except queue.Empty:
+ return
+ callname, kwargs = eventcall
+ assert callname, kwargs
+ method = "slave_" + callname
+ call = getattr(self, method)
+ self.log("calling method", method, kwargs)
+ call(**kwargs)
+
def pytest_collection(self):
# prohibit collection of test items in master process
return True
@@ -535,6 +550,7 @@ class DSession:
while not self.session_finished:
self.loop_once()
if self.shouldstop:
+ self.triggershutdown()
raise Interrupted(str(self.shouldstop))
return True The interaction with |
looks like a correct solution, but also points to the problem, there should be a state-machine that cannot exit until all event sources quit and the queue is drained |
An other possible effect of this is it also looks like xdist does not run all session-scoped teardowns properly when terminated early (due to either I've got fairly long but largely IO-bound tests for the integration of various services. To cut down on the wallclock runtime I'm trying to make it work with xdist and that's largely working, however I've got some set up and teardown of external services using session-scoped fixtures[0] and I regularly find out that some of the service teardowns did not work (and I assume not run) which often breaks the next run if I don't notice. [0] it's slightly less efficient but fine that these create separate instances of the external services so each xdist worker having its own version of the fixture is not an issue |
It doesn't run any teardowns, not only session-scoped:
Executed with xdist:
Expected behavior (no
|
@rbierbasz i believe this is a reporting mistake due to the teardown running file and the error happening in the call this is possibly related to the report transfer ptorocol used in xdist and how we disconnect from items/serialize there |
@RonnyPfannschmidt OK, I tested setup and teardown with side effect (touching files) and the files were touched. Thanks. |
Thanks for verifying, |
Can confirm, seems like xdist doesn't like teardowns at all with |
FTR pytest-xdist needs to implement The master worker sends tests in batches for workers to execute, which report back each test status (success, failure, etc). With |
I have the same problem. Any solution? Thanks! |
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.
While investigating pytest-dev/pytest#442 I ran into an issue where xdist behaves differently than regular pytest.
Basically, it seems that when using
--exitfirst
or--maxfail=X
, in combination with-n X
, pytest (DSession
?) bails out before collecting the teardown report, so thepytest_runtest_logreport
doesn't get run.At first glance, it seems like the the plugin should flush any unread entries from the queue after telling the nodes to stop.
I'm willing to work on this if someone can verify that this makes sense and/or point me in the right direction :)
The text was updated successfully, but these errors were encountered: