Skip to content

Commit 3837c6d

Browse files
author
Sylvain MARIE
committed
Fixture closure is now correctly updated after append. Fixes #176
1 parent d7f6112 commit 3837c6d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pytest_cases/plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,13 @@ def __init__(self,
487487

488488
# save the fixture closure tree root
489489
self.tree = root_node
490+
# retrieve/sort fixture defs for quicker access
491+
self._update_fixture_defs()
490492

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

495498
# # also sort all partitions (note that we cannot rely on the order in all_fixture_defs when scopes are same!)
496499
# if LooseVersion(pytest.__version__) >= LooseVersion('3.5.0'):
@@ -581,6 +584,8 @@ def insert(self, index, fixture_name):
581584
if index == len(self):
582585
# append: supported
583586
self.tree.build_closure((fixture_name,))
587+
# update fixture defs
588+
self._update_fixture_defs()
584589
else:
585590
raise NotImplementedError("When fixture unions are present, inserting a fixture in the closure is "
586591
"non-trivial. Please report this so that we can find a suitable solution for "

pytest_cases/tests/pytest_extension/fixtures/fixture_unions/test_fixture_closure_edits.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ def test_super_closure_edits2():
5959
with pytest.raises(NotImplementedError):
6060
del super_closure[-1]
6161

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

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

0 commit comments

Comments
 (0)