Skip to content
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

[Advisory] IPytest + pytest-xdist does not work (ExitCode.NO_TESTS_COLLECTED: 5) #90

Closed
keen85 opened this issue Mar 4, 2023 · 3 comments

Comments

@keen85
Copy link

keen85 commented Mar 4, 2023

pytest-xdist is a plugin for pytest allowing to run tests in parallel.

I installed it via pip but I can't get it to run in combination with IPytest. I allways get ExitCode.NO_TESTS_COLLECTED: 5

I tried so far creating a ipynb notebook with the following cells:

Setup

import time
import ipytest

def test_first():
    time.sleep(3)
    assert True

def test_second():
    time.sleep(3)
    assert True

def test_third():
    time.sleep(3)
    assert True

Test 1: plain ipytest → works ✅

ipytest.autoconfig(addopts=[])
ipytest.run()
======================================= test session starts =======================================
platform win32 -- Python 3.10.10, pytest-7.2.2, pluggy-1.0.0
rootdir: ...
plugins: anyio-3.6.2, xdist-3.2.0
collected 3 items

t_bcf84451f8db4a55bde8bada6fc2f412.py 
.
.
.
                                                    [100%]

======================================== 3 passed in 9.05s ========================================
<ExitCode.OK: 0>

Test 2: ipytest + pytest-xdist → no tests are executed 🛑

ipytest.autoconfig(addopts=["--numprocesses=2"])
ipytest.run()
======================================= test session starts =======================================
platform win32 -- Python 3.10.10, pytest-7.2.2, pluggy-1.0.0
rootdir: ...
plugins: anyio-3.6.2, xdist-3.2.0
gw0 I / gw1 I
gw0 [0] / gw1 [0]


====================================== no tests ran in 0.71s ======================================
<ExitCode.NO_TESTS_COLLECTED: 5>

What am I doing wrong?

@chmp
Copy link
Owner

chmp commented Mar 5, 2023

Hi @keen85

Thanks for the report. With only a cursory glance, it seems like xdist could be hard to support: the plugin seems to start separate processes for parallelization. However a lot of the ipytest functionality relies on modifying the current interpreter state. I fear that there could be no way to pass forward this modified state to the started processes.

I will have a closer look at how python-xdist works in the coming days and investigate in detail what's going on.

@chmp
Copy link
Owner

chmp commented Mar 21, 2023

@keen85 unfortunately I'm pretty sure it's not possible to support pytest-xdist in ipytest. In their "how it works" section, it states explicitly that the collection is done in each worker thread. However, the tests defined inside the notebook are only available in the main process.

@chmp chmp closed this as completed Mar 21, 2023
@keen85
Copy link
Author

keen85 commented Mar 22, 2023

@chmp thanks for taking your time and digging into it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants