Skip to content

Commit db37a8f

Browse files
committed
Add regression test that prove why we need explicit parent tracking
1 parent d9c005c commit db37a8f

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/chaining_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ def test_multiple_chain_branches_on_same_root_are_supported():
3636
assert cat_that_meowed.roll() == "playful"
3737

3838

39+
def test_unstub_child_chain_then_reconfigure_does_not_leave_stale_root_stub():
40+
cat = mock()
41+
42+
when(cat).meow().purr().sleep().thenReturn("base")
43+
when(cat).meow().purr().sleep().thenReturn("override")
44+
45+
with when(cat).meow().purr():
46+
cat.meow().purr()
47+
48+
with pytest.raises(InvocationError) as exc:
49+
with when(cat).meow().purr().thenReturn("tmp"):
50+
cat.meow().purr()
51+
52+
assert str(exc.value) == "'purr' is already configured for chained stubbing."
53+
54+
unstub(cat.meow())
55+
56+
with when(cat).meow().purr().thenReturn("tmp"):
57+
assert cat.meow().purr() == "tmp"
58+
59+
assert cat.meow() is None
60+
61+
3962
def test_expectation_on_chain_applies_to_leaf():
4063
cat = mock()
4164

0 commit comments

Comments
 (0)