Skip to content

Skip optional-dependency tests instead of asserting absence - #48

Merged
seanwevans merged 4 commits into
mainfrom
claude/test-optional-deps-skip
Sep 3, 2026
Merged

seanwevans merged 4 commits into
mainfrom
claude/test-optional-deps-skip

Conversation

@seanwevans

Copy link
Copy Markdown
Owner

Turns the badge green. Environment coupling, not a bug in the runtime.

Problem

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.

Change

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 an unrelated pydot one and so needed two different skip conditions

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 — the rest of the round-trip still runs everywhere. As a side benefit this stops the test writing totem_private_key.pem, totem_public_key.pem and totem.logbook.jsonl into 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 the RuntimeError paths stay covered whether or not the packages are installed. Drop them if you'd rather keep the change minimal.

Verified both ways

Environment Result
packages installed 146 passed, 4 skipped
packages hidden from the import system 150 passed, 0 skipped

🤖 Generated with Claude Code

https://claude.ai/code/session_01K7BqQpyspK2owRy6g6SFxw


Generated by Claude Code

claude and others added 4 commits September 3, 2026 17:32
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
@seanwevans
seanwevans merged commit 8253df6 into main Sep 3, 2026
2 checks passed
@seanwevans
seanwevans deleted the claude/test-optional-deps-skip branch September 3, 2026 18:03
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.

2 participants