Repository navigation
Fix the optional-dependency guard for the hypothesmith fuzz test - #117
Merged
Merged
Conversation
The @settings/@given decorators run at import time and call into hypothesmith, so the existing @pytest.mark.skipif never took effect: without the optional deps the module raised NameError during collection, taking every other test in the file down with it. Guard the decorated definition on the import result instead, falling back to a visibly-skipped stub when hypothesmith is unavailable.
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.
The property-based fuzz test (
test_idempotent_any_syntatically_valid_python)is meant to be optional — it's guarded with
@pytest.mark.skipif(not hypothesmith, ...)so the suite still runs when thehypothesis/hypothesmithextras aren't installed. But that guard never takeseffect.
skipifonly marks an already-collected test. The decorators stacked above itrun at import time:
@settings(... suppress_health_check=HealthCheck.all())and@given(...)reference
settings,given,HealthCheck,st— names that only existwhen the
try: import hypothesmith / from hypothesis import ...succeeds.@given(src_contents=hypothesmith.from_grammar() | hypothesmith.from_node())calls into
hypothesmitheagerly.So without the optional deps, importing the test module raises
NameError: name 'settings' is not definedduring collection — which fails theentire
test_mccabe.py, taking every other test down with it. Theskipifis dead code.
Fix
Guard the decorated definition on the import result instead of relying on
skipif, with a visibly-skipped stub when the dep is absent:Verification
hypothesmith/hypothesis: the module now collects; the fuzztest reports as skipped; all other tests run. (Previously: collection error,
whole file failed.)
hypothesmith: the test is collected and passes (1000 examples).flake8 --max-line-length=88 test_mccabe.pyclean.