Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(warnings): trigger reset warnings at a better stack level #165

Merged
merged 1 commit into from
Mar 21, 2023

Conversation

mcous
Copy link
Owner

@mcous mcous commented Mar 19, 2023

#164 upgraded ruff to include more flake8 bugbear errors, which highlighted that the stacklevel argument to warnings.warn is not used by the warning checker. This results in warnings being attached to an unhelpful decoy-internal call-site.

This PR uses the stacklevel argument of warnings.warn to trigger the warnings at whatever level called decoy.reset. For pytest usage, this results in something like the following:

# before
/Users/mc/projects/decoy/decoy/warning_checker.py:60: MiscalledStubWarning: Stub was called but no matching rehearsal found.
Found 1 rehearsal:
1.	stub(1, 2, 3)
Found 1 call:
1.	stub(4, 5, 6)
  warn(MiscalledStubWarning(calls=unmatched, rehearsals=past_stubs))

# after
/Users/mc/projects/decoy/decoy/pytest_plugin.py:32: MiscalledStubWarning: Stub was called but no matching rehearsal found.
Found 1 rehearsal:
1.	stub(1, 2, 3)
Found 1 call:
1.	stub(4, 5, 6)
  decoy.reset()

@codecov
Copy link

codecov bot commented Mar 19, 2023

Codecov Report

Merging #165 (f921401) into main (97fb55b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #165   +/-   ##
=======================================
  Coverage   98.36%   98.36%           
=======================================
  Files          19       19           
  Lines         734      736    +2     
  Branches       87       87           
=======================================
+ Hits          722      724    +2     
  Misses         10       10           
  Partials        2        2           
Impacted Files Coverage Δ
decoy/errors.py 100.00% <ø> (ø)
decoy/matchers.py 89.09% <ø> (ø)
decoy/core.py 100.00% <100.00%> (ø)
decoy/warning_checker.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@mcous mcous merged commit 56863f5 into main Mar 21, 2023
@mcous mcous deleted the fix-warnings-stacklevel branch March 21, 2023 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant