From 4ea7bbc197de2af0938ff64423add33098ee7326 Mon Sep 17 00:00:00 2001 From: Roland Puntaier Date: Tue, 28 Nov 2017 16:47:12 +0100 Subject: [PATCH 1/7] fix issue #2920 --- _pytest/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/config.py b/_pytest/config.py index 1ae1ffd092b..499c8079d41 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -417,7 +417,7 @@ def import_plugin(self, modname): # _pytest prefix. assert isinstance(modname, (six.text_type, str)), "module name as text required, got %r" % modname modname = str(modname) - if self.get_plugin(modname) is not None: + if self.is_blocked(modname) or self.get_plugin(modname) is not None: return if modname in builtin_plugins: importspec = "_pytest." + modname From 9b7e4ab0c6541bdc0ec234c8833f8fa2149ee49a Mon Sep 17 00:00:00 2001 From: Roland Puntaier Date: Tue, 28 Nov 2017 16:56:59 +0100 Subject: [PATCH 2/7] prepare pull request for #2920 fix --- AUTHORS | 1 + changelog/2920.bugfix | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog/2920.bugfix diff --git a/AUTHORS b/AUTHORS index 34c6f64378b..44ae6aa43ab 100644 --- a/AUTHORS +++ b/AUTHORS @@ -186,3 +186,4 @@ Wouter van Ackooy Xuan Luong Xuecong Liao Zoltán Máté +Roland Puntaier diff --git a/changelog/2920.bugfix b/changelog/2920.bugfix new file mode 100644 index 00000000000..83143443e67 --- /dev/null +++ b/changelog/2920.bugfix @@ -0,0 +1 @@ +Fix issue about -p no: having no effect. From 4a840a7c09cf6b5e53d2df3bf3b6bb348b5ea63b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 28 Nov 2017 13:59:27 -0200 Subject: [PATCH 3/7] Fix formatting in CHANGELOG --- changelog/2920.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/2920.bugfix b/changelog/2920.bugfix index 83143443e67..c5a0fd59727 100644 --- a/changelog/2920.bugfix +++ b/changelog/2920.bugfix @@ -1 +1 @@ -Fix issue about -p no: having no effect. +Fix issue about `-p no:` having no effect. From 6843d45c516d1e0eb8e642b2085d39b4091c3374 Mon Sep 17 00:00:00 2001 From: Roland Puntaier Date: Tue, 28 Nov 2017 17:29:52 +0100 Subject: [PATCH 4/7] added test for #2920 fix --- testing/test_config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/testing/test_config.py b/testing/test_config.py index 246c5b71b9a..0211d55df8b 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -1,4 +1,5 @@ from __future__ import absolute_import, division, print_function +import sys import py import pytest @@ -483,8 +484,11 @@ def load(self): monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter) config = testdir.parseconfig("-p", "no:mytestplugin") - plugin = config.pluginmanager.getplugin("mytestplugin") - assert plugin is None + config.pluginmanager.import_plugin("mytestplugin") + #from _pytest.config import get_config + #pm = get_config().pluginmanager + #pm.import_plugin("mytestplugin") + assert "mytestplugin" not in sys.modules def test_cmdline_processargs_simple(testdir): From 833f33fa0cfd16885f0f93fb288cc8d18b761d8c Mon Sep 17 00:00:00 2001 From: Roland Puntaier Date: Tue, 28 Nov 2017 17:38:49 +0100 Subject: [PATCH 5/7] removed comments --- testing/test_config.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/testing/test_config.py b/testing/test_config.py index 0211d55df8b..de8465159b1 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -485,9 +485,6 @@ def load(self): monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter) config = testdir.parseconfig("-p", "no:mytestplugin") config.pluginmanager.import_plugin("mytestplugin") - #from _pytest.config import get_config - #pm = get_config().pluginmanager - #pm.import_plugin("mytestplugin") assert "mytestplugin" not in sys.modules From 2a75ae46c34ce88c4dde3e1a1c517eb35a98f7f5 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 28 Nov 2017 21:29:58 -0200 Subject: [PATCH 6/7] Improve test that blocks setuptools plugins from being loaded Make it a parametrized test to ensure all the mocked mechanisms in the test actually work as expected when we *do not* use "-p no:" --- testing/test_config.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/testing/test_config.py b/testing/test_config.py index de8465159b1..44b8c317a28 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -460,9 +460,12 @@ def load(self): testdir.parseconfig() -def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch): +@pytest.mark.parametrize('block_it', [True, False]) +def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch, block_it): pkg_resources = pytest.importorskip("pkg_resources") + plugin_module_placeholder = object() + def my_iter(name): assert name == "pytest11" @@ -478,14 +481,19 @@ class EntryPoint(object): dist = Dist() def load(self): - assert 0, "should not arrive here" + return plugin_module_placeholder return iter([EntryPoint()]) monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter) - config = testdir.parseconfig("-p", "no:mytestplugin") + args = ("-p", "no:mytestplugin") if block_it else () + config = testdir.parseconfig(*args) config.pluginmanager.import_plugin("mytestplugin") - assert "mytestplugin" not in sys.modules + if block_it: + assert "mytestplugin" not in sys.modules + assert config.pluginmanager.get_plugin('mytestplugin') is None + else: + assert config.pluginmanager.get_plugin('mytestplugin') is plugin_module_placeholder def test_cmdline_processargs_simple(testdir): From 5f1a7330b2c3a94b65aa8d5ad385026ed8380f2a Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 28 Nov 2017 21:36:17 -0200 Subject: [PATCH 7/7] Small fixes in changelog items --- changelog/2920.bugfix | 2 +- changelog/2949.trivial | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog/2920.bugfix b/changelog/2920.bugfix index c5a0fd59727..9c5217278ae 100644 --- a/changelog/2920.bugfix +++ b/changelog/2920.bugfix @@ -1 +1 @@ -Fix issue about `-p no:` having no effect. +Fix issue about ``-p no:`` having no effect. diff --git a/changelog/2949.trivial b/changelog/2949.trivial index 357d5825310..39789e72b7a 100644 --- a/changelog/2949.trivial +++ b/changelog/2949.trivial @@ -1 +1 @@ -iUpdate github "bugs" link in CONTRIBUTING.rst +Update github "bugs" link in CONTRIBUTING.rst