Address #3796 and add a test for it.

This commit is contained in:
turturica 2018-08-23 22:48:44 -07:00
parent 4d3c1ab4f0
commit 5f8b50c094
2 changed files with 75 additions and 5 deletions

View File

@ -597,14 +597,16 @@ class Package(Module):
if path.basename == "__init__.py" and path.dirpath() == this_path:
continue
for pkg_prefix in pkg_prefixes:
if pkg_prefix in path.parts() and pkg_prefix.join('__init__.py') != path:
skip = True
if skip:
continue
if path.isdir() and path.join('__init__.py').check(file=1):
pkg_prefixes.add(path)
for pkg_prefix in pkg_prefixes:
if pkg_prefix in path.parts() and pkg_prefix.join('__init__.py') == path:
skip = True
if skip:
continue
for x in self._collectfile(path):
yield x

View File

@ -3979,3 +3979,71 @@ class TestScopeOrdering(object):
items, _ = testdir.inline_genitems()
request = FixtureRequest(items[0])
assert request.fixturenames == "s1 p1 m1 m2 c1 f2 f1".split()
def test_multiple_packages(self, testdir):
"""Complex test involving multiple package fixtures. Make sure teardowns
are executed in order.
.
root
__init__.py
sub1
__init__.py
conftest.py
test_1.py
sub2
__init__.py
conftest.py
test_2.py
"""
root = testdir.mkdir("root")
root.join("__init__.py").write("values = []")
sub1 = root.mkdir("sub1")
sub1.ensure("__init__.py")
sub1.join("conftest.py").write(
dedent(
"""\
import pytest
from .. import values
@pytest.fixture(scope="package")
def fix():
values.append("pre-sub1")
yield values
values.pop()
"""
)
)
sub1.join("test_1.py").write(
dedent(
"""\
from .. import values
def test_1(fix):
assert values == ["pre-sub1"]
"""
)
)
sub2 = root.mkdir("sub2")
sub2.ensure("__init__.py")
sub2.join("conftest.py").write(
dedent(
"""\
import pytest
from .. import values
@pytest.fixture(scope="package")
def fix():
values.append("pre-sub2")
yield values
values.pop()
"""
)
)
sub2.join("test_2.py").write(
dedent(
"""\
from .. import values
def test_2(fix):
assert values == ["pre-sub2"]
"""
)
)
reprec = testdir.inline_run()
reprec.assertoutcome(passed=2)