Skip to content

Commit

Permalink
Fix incompatibility error with --pdb despite using -n0
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev committed Aug 14, 2023
1 parent bfd28ff commit 7c72808
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog/937.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug where plugin would raise an incompatibility error with ``--pdb`` despite using ``-n0``.
22 changes: 18 additions & 4 deletions src/xdist/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def pytest_configure(config):

# Create the distributed session in case we have a valid distribution
# mode and test environments.
if config.getoption("dist") != "no" and config.getoption("tx"):
if _is_distribution_mode(config):
from xdist.dsession import DSession

session = DSession(config)
Expand All @@ -252,8 +252,19 @@ def pytest_configure(config):
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)
def pytest_cmdline_main(config):
if config.option.distload:
config.option.dist = "load"

usepdb = config.getoption("usepdb", False) # a core option
if config.option.numprocesses in ("auto", "logical"):
if usepdb:
Expand All @@ -270,10 +281,13 @@ def pytest_cmdline_main(config):
if config.option.maxprocesses:
numprocesses = min(numprocesses, config.option.maxprocesses)
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
if not val("collectonly") and val("dist") != "no" and usepdb:
if not val("collectonly") and _is_distribution_mode(config) and usepdb:
raise pytest.UsageError(
"--pdb is incompatible with distributing tests; try using -n0 or -nauto."
) # noqa: E501
Expand Down
17 changes: 17 additions & 0 deletions testing/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ def test_dist_options(pytester: pytest.Pytester) -> None:
check_options(config)
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(
pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch
Expand Down

0 comments on commit 7c72808

Please sign in to comment.