Skip to content

Commit 2a75ae4

Browse files
committed
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:"
1 parent 833f33f commit 2a75ae4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

testing/test_config.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,12 @@ def load(self):
460460
testdir.parseconfig()
461461

462462

463-
def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch):
463+
@pytest.mark.parametrize('block_it', [True, False])
464+
def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch, block_it):
464465
pkg_resources = pytest.importorskip("pkg_resources")
465466

467+
plugin_module_placeholder = object()
468+
466469
def my_iter(name):
467470
assert name == "pytest11"
468471

@@ -478,14 +481,19 @@ class EntryPoint(object):
478481
dist = Dist()
479482

480483
def load(self):
481-
assert 0, "should not arrive here"
484+
return plugin_module_placeholder
482485

483486
return iter([EntryPoint()])
484487

485488
monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter)
486-
config = testdir.parseconfig("-p", "no:mytestplugin")
489+
args = ("-p", "no:mytestplugin") if block_it else ()
490+
config = testdir.parseconfig(*args)
487491
config.pluginmanager.import_plugin("mytestplugin")
488-
assert "mytestplugin" not in sys.modules
492+
if block_it:
493+
assert "mytestplugin" not in sys.modules
494+
assert config.pluginmanager.get_plugin('mytestplugin') is None
495+
else:
496+
assert config.pluginmanager.get_plugin('mytestplugin') is plugin_module_placeholder
489497

490498

491499
def test_cmdline_processargs_simple(testdir):

0 commit comments

Comments
 (0)