From c874872190fe5f9d2c71813dfdfac40ce08d3722 Mon Sep 17 00:00:00 2001 From: verdesmarald Date: Mon, 4 Sep 2017 14:25:42 +1000 Subject: [PATCH 1/4] Don't create DSession in collect-only mode --- xdist/plugin.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/xdist/plugin.py b/xdist/plugin.py index 93231e8..6f46ac1 100644 --- a/xdist/plugin.py +++ b/xdist/plugin.py @@ -91,14 +91,15 @@ def pytest_addhooks(pluginmanager): @pytest.mark.trylast def pytest_configure(config): - if config.getoption("dist") != "no": - from xdist.dsession import DSession - session = DSession(config) - config.pluginmanager.register(session, "dsession") - tr = config.pluginmanager.getplugin("terminalreporter") - tr.showfspath = False - if config.getoption("boxed"): - config.option.forked = True + if not config.getvalue("collectonly"): + if config.getoption("dist") != "no": + from xdist.dsession import DSession + session = DSession(config) + config.pluginmanager.register(session, "dsession") + tr = config.pluginmanager.getplugin("terminalreporter") + tr.showfspath = False + if config.getoption("boxed"): + config.option.forked = True @pytest.mark.tryfirst From c83f73e19c43fa3058d6d0e03b5051263352b133 Mon Sep 17 00:00:00 2001 From: verdesmarald Date: Mon, 4 Sep 2017 14:32:19 +1000 Subject: [PATCH 2/4] Add news file for bugfix --- changelog/5.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/5.bugfix diff --git a/changelog/5.bugfix b/changelog/5.bugfix new file mode 100644 index 0000000..a3e1711 --- /dev/null +++ b/changelog/5.bugfix @@ -0,0 +1 @@ +Fix issue where the -n option would still run distributed tests when pytest was run with the --collect-only option From 7674f6b186abf58ab37a5fda9b3d5a41c336c070 Mon Sep 17 00:00:00 2001 From: verdesmarald Date: Thu, 7 Sep 2017 16:05:25 +1000 Subject: [PATCH 3/4] Add tests for interactions between boxed, dist and collect-only. Re-enable parsing of the boxed option with collect-only --- testing/acceptance_test.py | 10 ++++++++++ testing/test_plugin.py | 27 +++++++++++++++++++++++++++ xdist/plugin.py | 17 ++++++++--------- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 42345d7..3a500c9 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -262,6 +262,16 @@ class TestDistribution: child.close() # assert ret == 2 + def test_dist_with_collectonly(self, testdir): + p1 = testdir.makepyfile(""" + def test_ok(): + pass + """) + result = testdir.runpytest(p1, "-n1", "--collect-only") + assert result.ret == 0 + result.stdout.fnmatch_lines([ + "*collected 1 item*", + ]) class TestDistEach: def test_simple(self, testdir): diff --git a/testing/test_plugin.py b/testing/test_plugin.py index 319e2ec..b7b0760 100644 --- a/testing/test_plugin.py +++ b/testing/test_plugin.py @@ -43,6 +43,33 @@ def test_auto_detect_cpus(testdir, monkeypatch): config = testdir.parseconfigure("-nauto") assert config.getoption('numprocesses') == 99 +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 + + config = testdir.parseconfigure("-n1", "--collect-only") + check_options(config) + assert not config.option.forked + + config = testdir.parseconfigure("-n1", "--boxed", "--collect-only") + check_options(config) + assert config.option.forked + +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") class TestDistOptions: def test_getxspecs(self, testdir): diff --git a/xdist/plugin.py b/xdist/plugin.py index 6f46ac1..a19515d 100644 --- a/xdist/plugin.py +++ b/xdist/plugin.py @@ -91,15 +91,14 @@ def pytest_addhooks(pluginmanager): @pytest.mark.trylast def pytest_configure(config): - if not config.getvalue("collectonly"): - if config.getoption("dist") != "no": - from xdist.dsession import DSession - session = DSession(config) - config.pluginmanager.register(session, "dsession") - tr = config.pluginmanager.getplugin("terminalreporter") - tr.showfspath = False - if config.getoption("boxed"): - config.option.forked = True + if config.getoption("dist") != "no" and not config.getvalue("collectonly"): + from xdist.dsession import DSession + session = DSession(config) + config.pluginmanager.register(session, "dsession") + tr = config.pluginmanager.getplugin("terminalreporter") + tr.showfspath = False + if config.getoption("boxed"): + config.option.forked = True @pytest.mark.tryfirst From 1e66af63899fec421fdb5bb0b8c3814726b6378a Mon Sep 17 00:00:00 2001 From: verdesmarald Date: Thu, 7 Sep 2017 16:39:21 +1000 Subject: [PATCH 4/4] Fix flake8 formatting errors --- testing/acceptance_test.py | 1 + testing/test_plugin.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 3a500c9..ab00e58 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -273,6 +273,7 @@ class TestDistribution: "*collected 1 item*", ]) + class TestDistEach: def test_simple(self, testdir): testdir.makepyfile(""" diff --git a/testing/test_plugin.py b/testing/test_plugin.py index b7b0760..13a51d1 100644 --- a/testing/test_plugin.py +++ b/testing/test_plugin.py @@ -43,6 +43,7 @@ def test_auto_detect_cpus(testdir, monkeypatch): config = testdir.parseconfigure("-nauto") assert config.getoption('numprocesses') == 99 + def test_boxed_with_collect_only(testdir): from xdist.plugin import pytest_cmdline_main as check_options config = testdir.parseconfigure("-n1", "--boxed") @@ -57,6 +58,7 @@ def test_boxed_with_collect_only(testdir): check_options(config) assert config.option.forked + 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 @@ -71,6 +73,7 @@ def test_dsession_with_collect_only(testdir): configure(config) assert not config.pluginmanager.hasplugin("dsession") + class TestDistOptions: def test_getxspecs(self, testdir): config = testdir.parseconfigure("--tx=popen", "--tx", "ssh=xyz")