From 8664fc41020e3c1019cad144c25952057b72e875 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 23 Jun 2015 07:53:32 +0200 Subject: [PATCH 1/3] Add a --noconftest option. --- _pytest/config.py | 4 ++++ _pytest/main.py | 3 +++ testing/test_conftest.py | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/_pytest/config.py b/_pytest/config.py index ccab94747..7f14256c6 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -120,6 +120,7 @@ class PytestPluginManager(PluginManager): self._path2confmods = {} self._conftestpath2mod = {} self._confcutdir = None + self._noconftest = False self.add_hookspecs(_pytest.hookspec) self.register(self) @@ -212,6 +213,7 @@ class PytestPluginManager(PluginManager): current = py.path.local() self._confcutdir = current.join(namespace.confcutdir, abs=True) \ if namespace.confcutdir else None + self._noconftest = namespace.noconftest testpaths = namespace.file_or_dir foundanchor = False for path in testpaths: @@ -236,6 +238,8 @@ class PytestPluginManager(PluginManager): self._getconftestmodules(x) def _getconftestmodules(self, path): + if self._noconftest: + self._path2confmods[path] = [] try: return self._path2confmods[path] except KeyError: diff --git a/_pytest/main.py b/_pytest/main.py index f9566712e..d84370e64 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -54,6 +54,9 @@ def pytest_addoption(parser): group.addoption('--confcutdir', dest="confcutdir", default=None, metavar="dir", help="only load conftest.py's relative to specified dir.") + group.addoption('--noconftest', action="store_true", + dest="noconftest", default=False, + help="Don't load any conftest.py files.") group = parser.getgroup("debugconfig", "test session debugging and configuration") diff --git a/testing/test_conftest.py b/testing/test_conftest.py index cc2c63ae0..dc77944fe 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -24,6 +24,7 @@ def conftest_setinitial(conftest, args, confcutdir=None): def __init__(self): self.file_or_dir = args self.confcutdir = str(confcutdir) + self.noconftest = False conftest._set_initial_conftests(Namespace()) class TestConftestValueAccessGlobal: @@ -161,6 +162,11 @@ def test_conftest_confcutdir(testdir): result = testdir.runpytest("-h", "--confcutdir=%s" % x, x) result.stdout.fnmatch_lines(["*--xyz*"]) +def test_no_conftest(testdir): + testdir.makeconftest("assert 0") + result = testdir.runpytest("--noconftest") + assert result.ret == 0 + def test_conftest_existing_resultlog(testdir): x = testdir.mkdir("tests") x.join("conftest.py").write(py.code.Source(""" From 8e0589af6912c392bfd3fab2868105e7d353813e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 23 Jun 2015 09:47:07 +0200 Subject: [PATCH 2/3] Add changelog entry. --- CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 824501c8b..5261f20f7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -65,6 +65,8 @@ - fix issue741: make running output from testdir.run copy/pasteable Thanks Bruno Oliveira. +- add a new ``--noconftest`` argument which ignores all ``conftest.py`` files. + 2.7.2 (compared to 2.7.1) ----------------------------- From f78b6df8bc2d8df037a7e1f6496e87cb8d99ba36 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 23 Jun 2015 14:05:44 +0200 Subject: [PATCH 3/3] Return an empty list directly. --- _pytest/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/config.py b/_pytest/config.py index 7f14256c6..b358cfd4c 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -239,7 +239,7 @@ class PytestPluginManager(PluginManager): def _getconftestmodules(self, path): if self._noconftest: - self._path2confmods[path] = [] + return [] try: return self._path2confmods[path] except KeyError: