Skip to content

Commit

Permalink
fix(warnings): trigger reset warnings at a better stack level (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous committed Mar 21, 2023
1 parent 3135376 commit 56863f5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions decoy/warning_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
WhenRehearsal,
match_event,
)
from .warnings import MiscalledStubWarning, RedundantVerifyWarning
from .warnings import DecoyWarning, MiscalledStubWarning, RedundantVerifyWarning


class WarningChecker:
Expand Down Expand Up @@ -57,9 +57,9 @@ def _check_no_miscalled_stubs(all_events: Sequence[AnySpyEvent]) -> None:
):
unmatched = [*unmatched, call]
if index == len(spy_calls) - 1:
warn(MiscalledStubWarning(calls=unmatched, rehearsals=past_stubs))
_warn(MiscalledStubWarning(calls=unmatched, rehearsals=past_stubs))
elif isinstance(call, WhenRehearsal) and len(unmatched) > 0:
warn(MiscalledStubWarning(calls=unmatched, rehearsals=past_stubs))
_warn(MiscalledStubWarning(calls=unmatched, rehearsals=past_stubs))
unmatched = []


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

for vr in verify_rehearsals:
if any(wr for wr in when_rehearsals if wr == vr):
warn(RedundantVerifyWarning(rehearsal=vr))
_warn(RedundantVerifyWarning(rehearsal=vr))

def _warn(warning: DecoyWarning) -> None:
"""Trigger a warning, at the stack level of whatever called `Decoy.reset`."""
warn(warning, stacklevel=6)

0 comments on commit 56863f5

Please sign in to comment.