Skip to content

Commit

Permalink
Fixture closure is now correctly updated after append. Fixes #176
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain MARIE committed Jan 25, 2021
1 parent d7f6112 commit 3837c6d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pytest_cases/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,13 @@ def __init__(self,

# save the fixture closure tree root
self.tree = root_node
# retrieve/sort fixture defs for quicker access
self._update_fixture_defs()

def _update_fixture_defs(self):
# get a list of all fixture defs, for quicker access (and sorted)
# sort by scope as in pytest fixture closure creator, if scope information is available
all_fixture_defs = root_node.get_all_fixture_defs(drop_fake_fixtures=False, try_to_sort=True)
all_fixture_defs = self.tree.get_all_fixture_defs(drop_fake_fixtures=False, try_to_sort=True)

# # also sort all partitions (note that we cannot rely on the order in all_fixture_defs when scopes are same!)
# if LooseVersion(pytest.__version__) >= LooseVersion('3.5.0'):
Expand Down Expand Up @@ -581,6 +584,8 @@ def insert(self, index, fixture_name):
if index == len(self):
# append: supported
self.tree.build_closure((fixture_name,))
# update fixture defs
self._update_fixture_defs()
else:
raise NotImplementedError("When fixture unions are present, inserting a fixture in the closure is "
"non-trivial. Please report this so that we can find a suitable solution for "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ def test_super_closure_edits2():
with pytest.raises(NotImplementedError):
del super_closure[-1]

with pytest.raises(NotImplementedError):
super_closure.append('toto')
# now supported
super_closure.append('toto')
assert list(super_closure) == ['environment', 'a', 'request', 'b', 'toto']

with pytest.raises(NotImplementedError):
super_closure.insert(0, 'toto')

0 comments on commit 3837c6d

Please sign in to comment.