Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move checking of options to pytest_configure
This allows for `pytest -n 2 --pdb` to stop / help with errors
before/during `pytest_configure`.
It also appears to be sensible to check the config in the hook meant for
it, instead of in `pytest_cmdline_main`.
  • Loading branch information
blueyed committed Mar 31, 2020
commit 022e3e98955a9de88ac7e649f0638cb78bc410b7
6 changes: 4 additions & 2 deletions src/xdist/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ def pytest_addhooks(pluginmanager):

@pytest.mark.trylast
def pytest_configure(config):
_check_options(config)

if config.getoption("dist") != "no" and not config.getvalue("collectonly"):
from xdist.dsession import DSession

Expand All @@ -176,8 +178,8 @@ def pytest_configure(config):
config.option.forked = True


@pytest.mark.tryfirst
def pytest_cmdline_main(config):
def _check_options(config):
"""Kept separate for tests."""
usepdb = config.getoption("usepdb", False) # a core option
if isinstance(config.option.numprocesses, AutoInt):
config.option.numprocesses = 0 if usepdb else int(config.option.numprocesses)
Expand Down
13 changes: 1 addition & 12 deletions testing/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import py
import execnet
from xdist.plugin import _check_options as check_options
from xdist.workermanage import NodeManager


Expand All @@ -21,8 +22,6 @@ def test_pdb_can_be_used_before_configure(testdir):


def test_dist_options(testdir):
from xdist.plugin import pytest_cmdline_main as check_options

config = testdir.parseconfigure("-n 2")
check_options(config)
assert config.option.dist == "load"
Expand All @@ -42,7 +41,6 @@ def test_dist_options(testdir):

def test_auto_detect_cpus(testdir, monkeypatch):
import os
from xdist.plugin import pytest_cmdline_main as check_options

if hasattr(os, "sched_getaffinity"):
monkeypatch.setattr(os, "sched_getaffinity", lambda _pid: set(range(99)))
Expand Down Expand Up @@ -71,8 +69,6 @@ def test_auto_detect_cpus(testdir, monkeypatch):


def test_boxed_with_collect_only(testdir):
from xdist.plugin import pytest_cmdline_main as check_options

config = testdir.parseconfigure("-n1", "--boxed")
check_options(config)
assert config.option.forked
Expand All @@ -87,17 +83,10 @@ def test_boxed_with_collect_only(testdir):


def test_dsession_with_collect_only(testdir):
from xdist.plugin import pytest_cmdline_main as check_options
from xdist.plugin import pytest_configure as configure

config = testdir.parseconfigure("-n1")
check_options(config)
configure(config)
assert config.pluginmanager.hasplugin("dsession")

config = testdir.parseconfigure("-n1", "--collect-only")
check_options(config)
configure(config)
assert not config.pluginmanager.hasplugin("dsession")


Expand Down