From dc90c9108fd8cc65bc76da7a6d71b6ed66c40256 Mon Sep 17 00:00:00 2001 From: turturica Date: Fri, 20 Apr 2018 17:15:09 -0700 Subject: [PATCH] Collapse all parent nested package fixtures when pointing to a sub-node. Example: Given this hierarchy: p1.s1.s2.s3 I want to run pytest p1/s1/s2/s3/foo.py If there are any package fixtures defined at p1..s2 levels, they should also be executed. --- _pytest/fixtures.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/_pytest/fixtures.py b/_pytest/fixtures.py index e4bb91514..e9d032f92 100644 --- a/_pytest/fixtures.py +++ b/_pytest/fixtures.py @@ -75,10 +75,11 @@ def get_scope_package(node, fixturedef): cls = node.Package current = node fixture_package_name = os.path.join(fixturedef.baseid, '__init__.py') - while current and type(current) is not cls or \ - fixture_package_name != current.nodeid: + while current and (type(current) is not cls or \ + fixture_package_name != current.nodeid): current = current.parent - assert current + if current is None: + return node.session return current