fix(tests): add pytest.importorskip guards to fix 9 collection errors - #30
Open
pt-act wants to merge 1 commit into
Open
fix(tests): add pytest.importorskip guards to fix 9 collection errors#30pt-act wants to merge 1 commit into
pt-act wants to merge 1 commit into
Conversation
wallbreaker_mcp/server.py: - wb_seed_list now includes builtin static categories as fallback when any source-specific query returns 0 external categories (was only on source='all'). Fixes AC4 for source='harmbench' when HarmBench data isn't cached. pyproject.toml: - Add hypothesis>=6.0 to [dependency-groups] dev (was only in [project.optional-dependencies] dev, not installed by uv sync) tests/ (9 files): - Add pytest.importorskip guards for optional deps (hypothesis, fastapi, PIL/Pillow) so tests skip gracefully instead of erroring during collection - Affected: test_security_properties, test_audit_remediation, test_tg1..tg7, test_typographic Result: 0 collection errors (was 9), 60 skipped, 1173 passed, 16 pre-existing failures (test_session_card, test_tg5_harden)
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.
wallbreaker_mcp/server.py:
pyproject.toml:
tests/ (9 files):
Result: 0 collection errors (was 9), 60 skipped, 1173 passed, 16 pre-existing failures (test_session_card, test_tg5_harden)
Summary
Adds
pytest.importorskip(...)guards to three test modules so the suite collects cleanly when optional deps are absent, instead of erroring during collection. Small, self-contained test-infrastructure fix — no production code changes.Problem
When the test environment is missing an optional dependency (
hypothesis,fastapi, orPillow), the affected modules import it at module top-level. Pytest then fails during collection (before any test runs), reporting errors rather than skips. On a minimal install this produced 9 collection errors.Fix
Three one-line additions / one cleanup (
+3 / -1):tests/pbt/test_security_properties.py— guardimportorskip('hypothesis')beforefrom hypothesis import ...tests/test_audit_remediation.py— guardimportorskip('fastapi')andimportorskip('hypothesis')tests/test_tg2_context.py— drop a redundant bareimport pytestthat preceded an existingimportorskiplineVerification
Fresh venv,
uv sync --frozen+uv run pytestonmain:Full suite after the fix (fresh venv, optional deps installed): 1 failed, 1485 passed, 55 skipped, 31 xfailed. The single remaining failure (
test_ac08_wb_attack_dispatches_existing_strategy_engineintest_wallbreaker_mcp.py) is pre-existing onmain— it assertsendpoint.model == "gpt-4o"against a dispatch path whose mock returns a different model, unrelated to this change. Confirmed it fails identically on pristinemainwithout this patch.Scope note
The original internal commit also carried a
wallbreaker_mcp/server.pystatic-fallback tweak and apyproject.tomldev-dep entry; those pieces are already present onmain, so the only net change required for the collection fix is the test-file guards shipped here. Kept to a single focused commit to make review trivial.Checklist
mainrm -rf .venv && uv sync --frozen)test_ac08failure confirmed unrelated