pytest-dev / pytest-dev/pytest-xdist

Geven monkey patching not being set in subprocesses

Open
#1,069 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.9k
Forks
287
Avg merge
9h 30m
Merged PRs (30d)
2

Description

Hi,

I have a simple test file of:

from gevent.monkey import is_module_patched, saved


def test_auto():
    if not is_module_patched("threading"):
        print(saved)
        print(saved.keys())
        exit("not patched!")


When I run pytest normally with monkey patching it works:

python -m gevent.monkey --module pytest

But running with xdist it breaks:

❯ python -m gevent.monkey --module pytest -n auto
==================================================================================================================================================================== test session starts ====================================================================================================================================================================
platform linux -- Python 3.12.2, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/myhome/Desktop/stream/xdist-gevent
configfile: pyproject.toml
plugins: xdist-3.5.0
12 workers [1 item]       
F                                                                                                                                                                                                                                                                                                                                                     [100%]
========================================================================================================================================================================= FAILURES ==========================================================================================================================================================================
_________________________________________________________________________________________________________________________________________________________________________ test_auto _________________________________________________________________________________________________________________________________________________________________________
[gw0] linux -- Python 3.12.2 /home/myhome/.cache/pypoetry/virtualenvs/xdist-gevent-hYN2y4Ul-py3.12/bin/python

    def test_auto():
        if not is_module_patched("threading"):
            print(saved)
            print(saved.keys())
>           exit("not patched!")

tests/test_some.py:8: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = Use exit() or Ctrl-D (i.e. EOF) to exit, code = 'not patched!'

>   ???
E   SystemExit: not patched!

<frozen _sitebuiltins>:26: SystemExit
------------------------------------------------------------------------------------------------------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------------------------------------------------------------------------------------------------------
{}
dict_keys([])
================================================================================================================================================================== short test summary info ==================================================================================================================================================================
FAILED tests/test_some.py::test_auto - SystemExit: not patched!
===================================================================================================================================================================== 1 failed in 0.88s =====================================================================================================================================================================

How can I monkey patch the workers too?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with tests/test_some.py using python -m gevent.monkey --module pytest -n auto, then inspect how pytest-xdist starts its workers and how gevent monkey patching is applied. Done means the worker process observes the expected patching behavior, with regression coverage for the shown command.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.