pytest-xdist
pytest-xdist copied to clipboard
Question: Is it expected, that the tests run in the main thread?
I have some code that registers signals, basically starting it's own thread.
This needs to be in the main thread, since signals only work there. Once every, maybe, 30 executions in my CI an assert triggers, that my code (and thereby the test) was not executed on the main thread.
Is there a way to reliably make that happen? How come this is so rare? Could the CI and maybe hyperthreading have something to do with it?
Can you provide any more information to reproduce this? What version of xdist are you using? What options?
That issue got introduced when execnet got thread models I believe, I suggest trying older versions of execnet
I know the problem you are facing, occasionally a worker comes online with both MainThread and _DummyThread, I learned this the hard way using interrupting-cow, we just rolled our own slightly worse solution and everything works as normal
I got the same problem. My tests are expected to be run in main thread. I'm exploring solution here. Would using pytest-ordering ensures that tests are run in main thread? I assume that it ensures the order and therefore run tests sequentially. Hence, there is no need to bring up new threads.
@kimyen the issue is that modern execnet no longer guarantees that certain code runs in the main thread, and thus it creates a problem for such test
@RonnyPfannschmidt , do you suggest any workaround for this problem? Or if there is a version of pytest-xdist that doesn't have this problem? Or which version of execnet has this problem? We do have any direct dependency on execnet, but maybe pytest-xdist should specifies a fix version to execnet.
This looks the same as https://github.com/pytest-dev/pytest-xdist/issues/620 which was opened later but has had more attention. Also see https://github.com/pytest-dev/execnet/issues/96.