Make the hypothesis plugin check laws from user-defined interfaces too#2060
Merged
sobolevn merged 6 commits intodry-python:masterfrom Mar 9, 2025
Merged
Conversation
When running property tests for an container, we register it as the strategy for each ancestor interface with laws. However, we do that only for modules in `returns.`, which means that lawful interfaces written by users will not be resolved. This commit just demonstrates the current state.
Right now, it just gets all MRO classes, and it misses interfaces defined outside `returns`. Will tackle that in the next commit.
Earlier, we were restricting it to any class within `returns`. Main user-visible change: We now include `Lawful` ancestors outside `returns`.
We check that the interface class actually has laws. This should eliminate any false positives that come from patching interfaces that were defined outside `returns`. Added a `_ParentWrapper` to test that it doesn't show up. (It did before the change in this commit.) Add to CHANGELOG and the hypothesis plugins page.
sobolevn
reviewed
Mar 9, 2025
Member
sobolevn
left a comment
There was a problem hiding this comment.
Thanks! Just one minor suggestion.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2060 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 80 81 +1
Lines 2485 2576 +91
Branches 437 44 -393
==========================================
+ Hits 2485 2576 +91 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have made things!
Thanks for the thoughtful and convenient plugin for running interface laws.
I found, however, that the plugin was not running the laws for an interface I defined myself. So, I decided to add that behavior.
Main changes:
returnsmodule. This is the user-visible change.hypothesisplugin, for each property test, we patch the interface with the container strategy:Checklist
CHANGELOG.mdRelated issues