Skip to content

Commit 56863f5

Browse files
authored
fix(warnings): trigger reset warnings at a better stack level (#165)
1 parent 3135376 commit 56863f5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

decoy/warning_checker.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
WhenRehearsal,
1111
match_event,
1212
)
13-
from .warnings import MiscalledStubWarning, RedundantVerifyWarning
13+
from .warnings import DecoyWarning, MiscalledStubWarning, RedundantVerifyWarning
1414

1515

1616
class WarningChecker:
@@ -57,9 +57,9 @@ def _check_no_miscalled_stubs(all_events: Sequence[AnySpyEvent]) -> None:
5757
):
5858
unmatched = [*unmatched, call]
5959
if index == len(spy_calls) - 1:
60-
warn(MiscalledStubWarning(calls=unmatched, rehearsals=past_stubs))
60+
_warn(MiscalledStubWarning(calls=unmatched, rehearsals=past_stubs))
6161
elif isinstance(call, WhenRehearsal) and len(unmatched) > 0:
62-
warn(MiscalledStubWarning(calls=unmatched, rehearsals=past_stubs))
62+
_warn(MiscalledStubWarning(calls=unmatched, rehearsals=past_stubs))
6363
unmatched = []
6464

6565

@@ -69,4 +69,8 @@ def _check_no_redundant_verify(all_calls: Sequence[AnySpyEvent]) -> None:
6969

7070
for vr in verify_rehearsals:
7171
if any(wr for wr in when_rehearsals if wr == vr):
72-
warn(RedundantVerifyWarning(rehearsal=vr))
72+
_warn(RedundantVerifyWarning(rehearsal=vr))
73+
74+
def _warn(warning: DecoyWarning) -> None:
75+
"""Trigger a warning, at the stack level of whatever called `Decoy.reset`."""
76+
warn(warning, stacklevel=6)

0 commit comments

Comments
 (0)