From 913a2da6e52b6f2395b19c3163200726070b449d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 8 Feb 2019 18:03:45 +0100 Subject: [PATCH 1/3] Fix handling of collect_ignore from parent conftest `_collectfile` should be called on files only. Fixes https://github.com/pytest-dev/pytest/issues/4592. --- changelog/4592.bugfix.rst | 1 + src/_pytest/main.py | 1 + src/_pytest/python.py | 12 +++++++----- testing/test_collection.py | 13 +++++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 changelog/4592.bugfix.rst diff --git a/changelog/4592.bugfix.rst b/changelog/4592.bugfix.rst new file mode 100644 index 000000000..f1eaae7eb --- /dev/null +++ b/changelog/4592.bugfix.rst @@ -0,0 +1 @@ +Fix handling of ``collect_ignore`` via parent ``conftest.py``. diff --git a/src/_pytest/main.py b/src/_pytest/main.py index d0d826bb6..68d5bac40 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -607,6 +607,7 @@ class Session(nodes.FSCollector): yield y def _collectfile(self, path, handle_dupes=True): + assert path.isfile() ihook = self.gethookproxy(path) if not self.isinitpath(path): if ihook.pytest_ignore_collect(path=path, config=self.config): diff --git a/src/_pytest/python.py b/src/_pytest/python.py index aaa49f7dd..48962d137 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -599,6 +599,7 @@ class Package(Module): return proxy def _collectfile(self, path, handle_dupes=True): + assert path.isfile() ihook = self.gethookproxy(path) if not self.isinitpath(path): if ihook.pytest_ignore_collect(path=path, config=self.config): @@ -642,11 +643,12 @@ class Package(Module): ): continue - if path.isdir() and path.join("__init__.py").check(file=1): - pkg_prefixes.add(path) - - for x in self._collectfile(path): - yield x + if path.isdir(): + if path.join("__init__.py").check(file=1): + pkg_prefixes.add(path) + else: + for x in self._collectfile(path): + yield x def _get_xunit_setup_teardown(holder, attr_name, param_obj=None): diff --git a/testing/test_collection.py b/testing/test_collection.py index 36e8a69ce..329182b0f 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -1144,3 +1144,16 @@ def test_collect_symlink_out_of_tree(testdir): ] ) assert result.ret == 0 + + +def test_collectignore_via_conftest(testdir, monkeypatch): + """collect_ignore in parent conftest skips importing child (issue #4592).""" + tests = testdir.mkpydir("tests") + tests.ensure("conftest.py").write("collect_ignore = ['ignore_me']") + + ignore_me = tests.mkdir("ignore_me") + ignore_me.ensure("__init__.py") + ignore_me.ensure("conftest.py").write("assert 0, 'should_not_be_called'") + + result = testdir.runpytest() + assert result.ret == EXIT_NOTESTSCOLLECTED From 9be069f89969bc9287d83d8782bfed0353b2c3fd Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 8 Feb 2019 15:50:33 -0200 Subject: [PATCH 2/3] Use isolated_build option in tox.ini As per the excellent article by gaborbernat: https://www.bernat.tech/pep-517-518/ --- pyproject.toml | 1 + tox.ini | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d17b936c1..2a4cd65c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ requires = [ "setuptools-scm", "wheel", ] +build-backend = "setuptools.build_meta" [tool.towncrier] package = "pytest" diff --git a/tox.ini b/tox.ini index f67d06f18..347faf15c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,6 @@ [tox] -minversion = 2.0 +isolated_build = True +minversion = 3.3 distshare = {homedir}/.tox/distshare # make sure to update environment list in travis.yml and appveyor.yml envlist = From e191a65ebb493c65cce4d3ef9eb4d52908bf9a35 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 8 Feb 2019 20:51:39 +0100 Subject: [PATCH 3/3] tox: py37-freeze: use --no-use-pep517 for PyInstaller Fixes https://github.com/pytest-dev/pytest/issues/4750. --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index f67d06f18..75b3a8ed7 100644 --- a/tox.ini +++ b/tox.ini @@ -166,7 +166,9 @@ commands = [testenv:py37-freeze] changedir = testing/freeze +# Disable PEP 517 with pip, which does not work with PyInstaller currently. deps = + --no-use-pep517 pyinstaller commands = {envpython} create_executable.py