Skip to content

Commit 4f0879f

Browse files
committed
refactor internal finalization mechanics such that all fixture arguments
in a test invocation will have a corresponding FixtureDef instance. also fixes issue246 (again). simplify parametrized fixture teardown by making it work lazy: during the setup of a parametrized fixture instance any previously setup instance which was setup with a different param is torn down before setting up the new one.
1 parent 4b9dbd3 commit 4f0879f

File tree

7 files changed

+216
-169
lines changed

7 files changed

+216
-169
lines changed

CHANGELOG

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
Unreleased
22
-----------------------------------
33

4+
- simplified and fixed implementation for calling finalizers when
5+
parametrized fixtures or function arguments are involved. finalization
6+
is now performed lazily at setup time instead of in the "teardown phase".
7+
While this might sound odd at first, it helps to ensure that we are
8+
correctly handling setup/teardown even in complex code. User-level code
9+
should not be affected unless it's implementing the pytest_runtest_teardown
10+
hook and expecting certain fixture instances are torn down within (very
11+
unlikely and would have been unreliable anyway).
12+
13+
- fix issue246 (again) fix finalizer order to be LIFO on independent fixtures
14+
depending on a parametrized higher-than-function scoped fixture.
15+
(fix quite some effort so please bear with the complexity of this sentence :)
16+
417
- fix issue244 by implementing special index for parameters to only use
518
indices for paramentrized test ids
619

_pytest/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ def __init__(self, name, parent=None, config=None, session=None):
230230
#: allow adding of extra keywords to use for matching
231231
self.extra_keyword_matches = set()
232232

233+
# used for storing artificial fixturedefs for direct parametrization
234+
self._name2pseudofixturedef = {}
233235
#self.extrainit()
234236

235237
@property
@@ -365,6 +367,8 @@ def addfinalizer(self, fin):
365367
self.session._setupstate.addfinalizer(fin, self)
366368

367369
def getparent(self, cls):
370+
""" get the next parent node (including ourself)
371+
which is an instance of the given class"""
368372
current = self
369373
while current and not isinstance(current, cls):
370374
current = current.parent

0 commit comments

Comments
 (0)