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

Allow -n 0 to disable xdist even if --dist is specified #231

Closed
timj opened this issue Sep 3, 2017 · 5 comments
Closed

Allow -n 0 to disable xdist even if --dist is specified #231

timj opened this issue Sep 3, 2017 · 5 comments

Comments

@timj
Copy link
Contributor

timj commented Sep 3, 2017

Following the advice in #18 I'm experimenting with loadscope as a means to to pin some tests to a single subprocess. This works fine but to ensure that it works properly for developers who are going to type pytest from the command line when debugging, I need to put the --dist=loadscope into a setup.cfg file. The problem I now find is that any use of --dist mandates that -n or -tx is used:

$ pytest -v  --dist=load --fulltrace  tests/test_register.py 
============================= test session starts ==============================
platform darwin -- Python 3.6.0, pytest-3.2.0, py-1.4.34, pluggy-0.4.0 -- /Users/timj/work/lsstsw3/miniconda/bin/python
cachedir: .cache
rootdir: /Volumes/G-RAID with Thunderbolt/transient/lsstsw3/build/pipe_tasks, inifile: setup.cfg
plugins: session2file-0.1.9, forked-0.3.dev0+g1dd93f6.d20170815, xdist-1.19.2.dev0+g459d52e.d20170815, flake8-0.8.1
ERROR: MISSING test execution (tx) nodes: please specify --tx

I would be fine with this if I could add -n 0 to disable xdist completely regardless of the presence of --dist. This does not work, and gives the same error message as if no -n was used at all. If this worked then the command-line user of pytest will get the behavior they expect: no subprocess if they run pytest, correctly scoped tests if they add -n 4 to override the config file.

Is there any way that I can use a setup.cfg to use --dist=loadscope but only to activate this if a user specifies -n?

@timj timj changed the title Allow -n 0 to disable xdist even if --dist is specified Allow -n 0 to disable xdist even if --dist is specified Sep 3, 2017
@souliane
Copy link

I am concerned by this issue / change request, since I can't use a debugger when pytest-xdist runs with the --dist parameter set in my setup.cfg. I would expect that -n 0 completely disables xdist.

@kousu
Copy link

kousu commented Jan 19, 2021

I have this in my setup.cfg:

[tool:pytest]
addopts = --verbose --numprocesses auto --dist=loadscope
python_files = unit_testing/test_*.py unit_testing/cli/test_*.py

Running

 pytest -n0 -s -v .
====================================================================================== test session starts =======================================================================================
platform linux -- Python 3.6.12, pytest-6.2.1, py-1.10.0, pluggy-0.13.1 -- /home/kousu/src/neuropoly/spinalcordtoolbox/python/envs/venv_sct/bin/python
cachedir: .pytest_cache
rootdir: /home/kousu/src/neuropoly/spinalcordtoolbox, configfile: setup.cfg
plugins: forked-1.3.0, cov-2.10.1, console-scripts-1.1.0, xdist-2.2.0, cases-3.1.1
ERROR: MISSING test execution (tx) nodes: please specify --tx

If I change it to

[tool:pytest]
addopts = --verbose
python_files = unit_testing/test_*.py unit_testing/cli/test_*.py

Then it works:

$ pytest -n0 -s -v .
====================================================================================== test session starts =======================================================================================
platform linux -- Python 3.6.12, pytest-6.2.1, py-1.10.0, pluggy-0.13.1 -- /home/kousu/src/neuropoly/spinalcordtoolbox/python/envs/venv_sct/bin/python
cachedir: .pytest_cache
rootdir: /home/kousu/src/neuropoly/spinalcordtoolbox, configfile: setup.cfg
plugins: forked-1.3.0, cov-2.10.1, console-scripts-1.1.0, xdist-2.2.0, cases-3.1.1
collecting 14 items                                                                                                                                                                              
--
Spinal Cord Toolbox (git-ng/2957-fixtures-7bbce7ab7c113c0d9725fdf7ab8406ea432a9ae7*)

Smoothing factor: smooth=0.3703703703703704
Smoothing factor: smooth=0.3703703703703704
Smoothing factor: smooth=0.3703703703703704
Smoothing factor: smooth=0.3703703703703704
Smoothing factor: smooth=0.3703703703703704
Smoothing factor: smooth=0.3703703703703704
Smoothing factor: smooth=0.3703703703703704
Smoothing factor: smooth=0.011999999999999999
Smoothing factor: smooth=0.011999999999999999
Smoothing factor: smooth=0.011999999999999999
Smoothing factor: smooth=0.011999999999999999
Smoothing factor: smooth=0.011999999999999999
collecting 57 items                                                                                                                                                                              (private) matplotlib data path: /home/kousu/src/neuropoly/spinalcordtoolbox/python/envs/venv_sct/lib/python3.6/site-packages/matplotlib/mpl-data
matplotlib data path: /home/kousu/src/neuropoly/spinalcordtoolbox/python/envs/venv_sct/lib/python3.6/site-packages/matplotlib/mpl-data
CONFIGDIR=/home/kousu/.config/matplotlib
matplotlib version 3.3.3
interactive is False
platform is linux
[...]

I also expected -n 0 to completely disable xdist. But that's not totally true, is it, since eg the worker_id fixture still works.

@MetRonnie
Copy link

If you do pytest -n0 --dist no it seems to prevent the

ERROR: MISSING test execution (tx) nodes: please specify --tx

error

@timj
Copy link
Contributor Author

timj commented Jul 12, 2023

It looks like this problem was fixed long ago. Running pytest --dist=loadscope handles no -n just fine.

@timj timj closed this as completed Jul 12, 2023
@nicoddemus
Copy link
Member

Thanks!

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

No branches or pull requests

5 participants