Open ddorian opened 5 months ago
Currently there's no built-in way to auto monkepatch on startup of a worker
I think we would need to extend execmodels
Any hint how I can try to hard fix it? That codebase looks complex, hard to find my way around it.
No I'm rather unfamiliar with gevent and similar and currently not in a position to work on extra gestures regarding it
@ddorian perhaps you can implement pytest_configure()
and call monkey.patch_all()
explicitly:
def pytest_configure():
if os.environ.get("PYTEST_XDIST_WORKER", "").startswith("gw"):
from gevent import monkey
monkey.patch_all()
That made the process hang. So the underlying module is not compatible (or the patching was done too late).
#conftest.py
def pytest_configure(config):
import os
from gevent import monkey
print("sssssssssssssssssssssssssssssssssssssssss")
if os.environ.get("PYTEST_XDIST_WORKER", "").startswith("gw"):
monkey.patch_all()
exit("CONFIGURING!!!")
python -m gevent.monkey --module pytest -n 2
sssssssssssssssssssssssssssssssssssssssss
==================================================================================================================================================================== test session starts ====================================================================================================================================================================
platform linux -- Python 3.12.2, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/guru/Desktop/stream/xdist-gevent
configfile: pyproject.toml
plugins: xdist-3.5.0
initialized: 2/2 workers
or the patching was done too late
Ahh possibly this then. You might try @hookimpl(tryfirst=True)
to see if it helps, but other than that I'm out of ideas I'm afraid.
Ahh possibly this then. You might try @hookimpl(tryfirst=True) to see if it helps,
Still stuck.
but other than that I'm out of ideas I'm afraid.
I just need a way to execute the monkey patching first then when the worker is started, but can't understand the code of execnet to see where it happens.
This pretty much needs a new execmodels that invokes the patches on usage
Hi,
I have a simple test file of:
When I run pytest normally with monkey patching it works:
But running with xdist it breaks:
How can I monkey patch the workers too?