Fix incompatibility error with --pdb despite using -n0 (#938)
Fixes #937
This commit is contained in:
1
changelog/937.bugfix
Normal file
1
changelog/937.bugfix
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Fix a bug where plugin would raise an incompatibility error with ``--pdb`` despite using ``-n0``.
|
||||||
@@ -233,7 +233,7 @@ def pytest_configure(config):
|
|||||||
|
|
||||||
# Create the distributed session in case we have a valid distribution
|
# Create the distributed session in case we have a valid distribution
|
||||||
# mode and test environments.
|
# mode and test environments.
|
||||||
if config.getoption("dist") != "no" and config.getoption("tx"):
|
if _is_distribution_mode(config):
|
||||||
from xdist.dsession import DSession
|
from xdist.dsession import DSession
|
||||||
|
|
||||||
session = DSession(config)
|
session = DSession(config)
|
||||||
@@ -258,8 +258,19 @@ def pytest_configure(config):
|
|||||||
config.issue_config_time_warning(warning, 2)
|
config.issue_config_time_warning(warning, 2)
|
||||||
|
|
||||||
|
|
||||||
|
def _is_distribution_mode(config):
|
||||||
|
"""Return `True` if distribution mode is on, `False` otherwise.
|
||||||
|
|
||||||
|
:param config: the `pytest` `config` object
|
||||||
|
"""
|
||||||
|
return config.getoption("dist") != "no" and config.getoption("tx")
|
||||||
|
|
||||||
|
|
||||||
@pytest.hookimpl(tryfirst=True)
|
@pytest.hookimpl(tryfirst=True)
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
|
if config.option.distload:
|
||||||
|
config.option.dist = "load"
|
||||||
|
|
||||||
usepdb = config.getoption("usepdb", False) # a core option
|
usepdb = config.getoption("usepdb", False) # a core option
|
||||||
if config.option.numprocesses in ("auto", "logical"):
|
if config.option.numprocesses in ("auto", "logical"):
|
||||||
if usepdb:
|
if usepdb:
|
||||||
@@ -276,10 +287,13 @@ def pytest_cmdline_main(config):
|
|||||||
if config.option.maxprocesses:
|
if config.option.maxprocesses:
|
||||||
numprocesses = min(numprocesses, config.option.maxprocesses)
|
numprocesses = min(numprocesses, config.option.maxprocesses)
|
||||||
config.option.tx = ["popen"] * numprocesses
|
config.option.tx = ["popen"] * numprocesses
|
||||||
if config.option.distload:
|
|
||||||
config.option.dist = "load"
|
if config.option.numprocesses == 0:
|
||||||
|
config.option.dist = "no"
|
||||||
|
config.option.tx = []
|
||||||
|
|
||||||
val = config.getvalue
|
val = config.getvalue
|
||||||
if not val("collectonly") and val("dist") != "no" and usepdb:
|
if not val("collectonly") and _is_distribution_mode(config) and usepdb:
|
||||||
raise pytest.UsageError(
|
raise pytest.UsageError(
|
||||||
"--pdb is incompatible with distributing tests; try using -n0 or -nauto."
|
"--pdb is incompatible with distributing tests; try using -n0 or -nauto."
|
||||||
) # noqa: E501
|
) # noqa: E501
|
||||||
|
|||||||
@@ -48,6 +48,23 @@ def test_dist_options(pytester: pytest.Pytester) -> None:
|
|||||||
check_options(config)
|
check_options(config)
|
||||||
assert config.option.dist == "load"
|
assert config.option.dist == "load"
|
||||||
|
|
||||||
|
config = pytester.parseconfigure("--numprocesses", "0")
|
||||||
|
check_options(config)
|
||||||
|
assert config.option.dist == "no"
|
||||||
|
assert config.option.tx == []
|
||||||
|
|
||||||
|
config = pytester.parseconfigure("--numprocesses", "0", "-d")
|
||||||
|
check_options(config)
|
||||||
|
assert config.option.dist == "no"
|
||||||
|
assert config.option.tx == []
|
||||||
|
|
||||||
|
config = pytester.parseconfigure(
|
||||||
|
"--numprocesses", "0", "--dist", "each", "--tx", "2*popen"
|
||||||
|
)
|
||||||
|
check_options(config)
|
||||||
|
assert config.option.dist == "no"
|
||||||
|
assert config.option.tx == []
|
||||||
|
|
||||||
|
|
||||||
def test_auto_detect_cpus(
|
def test_auto_detect_cpus(
|
||||||
pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch
|
pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch
|
||||||
@@ -77,13 +94,8 @@ def test_auto_detect_cpus(
|
|||||||
check_options(config)
|
check_options(config)
|
||||||
assert config.getoption("numprocesses") == 99
|
assert config.getoption("numprocesses") == 99
|
||||||
|
|
||||||
config = pytester.parseconfigure("-nauto", "--pdb")
|
for numprocesses in (0, "auto", "logical"):
|
||||||
check_options(config)
|
config = pytester.parseconfigure(f"-n{numprocesses}", "--pdb")
|
||||||
assert config.getoption("usepdb")
|
|
||||||
assert config.getoption("numprocesses") == 0
|
|
||||||
assert config.getoption("dist") == "no"
|
|
||||||
|
|
||||||
config = pytester.parseconfigure("-nlogical", "--pdb")
|
|
||||||
check_options(config)
|
check_options(config)
|
||||||
assert config.getoption("usepdb")
|
assert config.getoption("usepdb")
|
||||||
assert config.getoption("numprocesses") == 0
|
assert config.getoption("numprocesses") == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user