Improve behavior of -n=auto with --pdb option
This commit is contained in:
1
changelog/415.feature
Normal file
1
changelog/415.feature
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Improve behavior of ``--numprocesses=auto`` to work well with ``--pdb`` option.
|
||||||
@@ -36,6 +36,7 @@ def test_dist_options(testdir):
|
|||||||
|
|
||||||
def test_auto_detect_cpus(testdir, monkeypatch):
|
def test_auto_detect_cpus(testdir, monkeypatch):
|
||||||
import os
|
import os
|
||||||
|
from xdist.plugin import pytest_cmdline_main as check_options
|
||||||
|
|
||||||
if hasattr(os, "sched_getaffinity"):
|
if hasattr(os, "sched_getaffinity"):
|
||||||
monkeypatch.setattr(os, "sched_getaffinity", lambda _pid: set(range(99)))
|
monkeypatch.setattr(os, "sched_getaffinity", lambda _pid: set(range(99)))
|
||||||
@@ -52,6 +53,11 @@ def test_auto_detect_cpus(testdir, monkeypatch):
|
|||||||
config = testdir.parseconfigure("-nauto")
|
config = testdir.parseconfigure("-nauto")
|
||||||
assert config.getoption("numprocesses") == 99
|
assert config.getoption("numprocesses") == 99
|
||||||
|
|
||||||
|
config = testdir.parseconfigure("-nauto", "--pdb")
|
||||||
|
check_options(config)
|
||||||
|
assert config.getoption("usepdb")
|
||||||
|
assert config.getoption("numprocesses") == 0
|
||||||
|
|
||||||
monkeypatch.delattr(os, "sched_getaffinity", raising=False)
|
monkeypatch.delattr(os, "sched_getaffinity", raising=False)
|
||||||
monkeypatch.setenv("TRAVIS", "true")
|
monkeypatch.setenv("TRAVIS", "true")
|
||||||
config = testdir.parseconfigure("-nauto")
|
config = testdir.parseconfigure("-nauto")
|
||||||
|
|||||||
@@ -27,10 +27,14 @@ def auto_detect_cpus():
|
|||||||
return n if n else 1
|
return n if n else 1
|
||||||
|
|
||||||
|
|
||||||
|
class AutoInt(int):
|
||||||
|
"""Mark value as auto-detected."""
|
||||||
|
|
||||||
|
|
||||||
def parse_numprocesses(s):
|
def parse_numprocesses(s):
|
||||||
if s == "auto":
|
if s == "auto":
|
||||||
return auto_detect_cpus()
|
return AutoInt(auto_detect_cpus())
|
||||||
else:
|
elif s is not None:
|
||||||
return int(s)
|
return int(s)
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +49,7 @@ def pytest_addoption(parser):
|
|||||||
type=parse_numprocesses,
|
type=parse_numprocesses,
|
||||||
help="shortcut for '--dist=load --tx=NUM*popen', "
|
help="shortcut for '--dist=load --tx=NUM*popen', "
|
||||||
"you can use 'auto' here for auto detection CPUs number on "
|
"you can use 'auto' here for auto detection CPUs number on "
|
||||||
"host system",
|
"host system and it will be 0 when used with --pdb",
|
||||||
)
|
)
|
||||||
group.addoption(
|
group.addoption(
|
||||||
"--maxprocesses",
|
"--maxprocesses",
|
||||||
@@ -177,6 +181,10 @@ def pytest_configure(config):
|
|||||||
|
|
||||||
@pytest.mark.tryfirst
|
@pytest.mark.tryfirst
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
|
usepdb = config.getoption("usepdb") # a core option
|
||||||
|
if isinstance(config.option.numprocesses, AutoInt):
|
||||||
|
config.option.numprocesses = 0 if usepdb else int(config.option.numprocesses)
|
||||||
|
|
||||||
if config.option.numprocesses:
|
if config.option.numprocesses:
|
||||||
if config.option.dist == "no":
|
if config.option.dist == "no":
|
||||||
config.option.dist = "load"
|
config.option.dist = "load"
|
||||||
@@ -188,11 +196,10 @@ def pytest_cmdline_main(config):
|
|||||||
config.option.dist = "load"
|
config.option.dist = "load"
|
||||||
val = config.getvalue
|
val = config.getvalue
|
||||||
if not val("collectonly"):
|
if not val("collectonly"):
|
||||||
usepdb = config.getoption("usepdb") # a core option
|
|
||||||
if val("dist") != "no":
|
if val("dist") != "no":
|
||||||
if usepdb:
|
if usepdb:
|
||||||
raise pytest.UsageError(
|
raise pytest.UsageError(
|
||||||
"--pdb is incompatible with distributing tests; try using -n0."
|
"--pdb is incompatible with distributing tests; try using -n0 or -nauto."
|
||||||
) # noqa: E501
|
) # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user