pytest-xdist icon indicating copy to clipboard operation
pytest-xdist copied to clipboard

Question: Is it expected, that the tests run in the main thread?

Open mchlnix opened this issue 6 years ago • 7 comments

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?

mchlnix avatar Sep 19 '19 13:09 mchlnix

Can you provide any more information to reproduce this? What version of xdist are you using? What options?

chrahunt avatar Nov 08 '19 03:11 chrahunt

That issue got introduced when execnet got thread models I believe, I suggest trying older versions of execnet

RonnyPfannschmidt avatar Nov 08 '19 12:11 RonnyPfannschmidt

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

symonk avatar Dec 03 '19 16:12 symonk

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 avatar Apr 23 '20 17:04 kimyen

@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 avatar Apr 23 '20 18:04 RonnyPfannschmidt

@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.

kimyen avatar Apr 23 '20 19:04 kimyen

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.

zmedico avatar Feb 15 '24 05:02 zmedico