Repository navigation
Skip optional-dependency tests instead of asserting absence - #48
Merged
Merged
Conversation
Four tests asserted that cryptography, networkx/matplotlib and pydot are NOT
installed, so they failed with DID NOT RAISE on any machine that happens to
have those packages. That is environment coupling, not a bug in the runtime.
tests/optional_deps.py detects each package with importlib.util.find_spec
and exports skipif markers. The degradation assertions now run only where
the dependency is genuinely missing:
- test_crypto_helpers_require_dependencies
- test_visualize_graph_requires_optional_dependencies
- test_visualization_guards
- test_graphviz_export_guard (split out of test_visualization_guards,
which mixed a networkx/matplotlib guard with a pydot one)
test_bitcode_round_trip_and_logging is not skipped: only its record_run
assertion was coupled, so that one call is now made only when cryptography
is absent. This also stops the test writing an RSA keypair and a logbook
into the working directory on machines that have it.
Skipping alone would have dropped coverage of the guard clauses, which
matters here because the coverage badge is generated from this suite. Two
replacements exercise the same guards on every machine by patching the
optional module bindings to None.
Verified both ways: with the packages installed, 146 pass and 4 skip; with
them hidden from the import system, all 150 pass and nothing skips.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7BqQpyspK2owRy6g6SFxw
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.
Turns the badge green. Environment coupling, not a bug in the runtime.
Problem
Four tests asserted that
cryptography,networkx/matplotlibandpydotare not installed, so they failed withDID NOT RAISEon any machine that happens to have those packages.Change
tests/optional_deps.pydetects each package withimportlib.util.find_specand exportsskipifmarkers. The degradation assertions now run only where the dependency is genuinely missing:test_crypto_helpers_require_dependenciestest_visualize_graph_requires_optional_dependenciestest_visualization_guardstest_graphviz_export_guard— split out oftest_visualization_guards, which mixed a networkx/matplotlib guard with an unrelated pydot one and so needed two different skip conditionstest_bitcode_round_trip_and_loggingis not skipped. Only itsrecord_runassertion was coupled, so that one call is now made only whencryptographyis absent — the rest of the round-trip still runs everywhere. As a side benefit this stops the test writingtotem_private_key.pem,totem_public_key.pemandtotem.logbook.jsonlinto the working directory on machines that have the package.One addition beyond the ask
Skipping alone drops coverage of the guard clauses, which matters here because the coverage badge is generated from this suite. Two replacement tests exercise the same guards on every machine by patching the optional module bindings to
None— so theRuntimeErrorpaths stay covered whether or not the packages are installed. Drop them if you'd rather keep the change minimal.Verified both ways
🤖 Generated with Claude Code
https://claude.ai/code/session_01K7BqQpyspK2owRy6g6SFxw
Generated by Claude Code