Skip to content

fix: exclude tests/ from Bandit's assert_used (B101) check - #99

Merged
petercorke merged 1 commit into
mainfrom
fix/bandit-skip-assert-check-in-tests
Aug 17, 2026
Merged

fix: exclude tests/ from Bandit's assert_used (B101) check#99
petercorke merged 1 commit into
mainfrom
fix/bandit-skip-assert-check-in-tests

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Codacy has been flagging every bare assert in the test suite (Prospector's Bandit integration, rule B101 "assert_used"). Bare assert is idiomatic pytest style (~45 uses across tests/), not a security concern there -- B101 exists to catch assert used for real validation in src/, where an assert can silently vanish under python -O. That's still a legitimate 48 findings, untouched by this change (tracked in #41).

Fix

[tool.bandit]
exclude_dirs = ["tests"]

Codacy's Python engine is Prospector, which wraps Bandit and honours this native pyproject.toml config directly -- no Codacy dashboard setting needed.

Verified

Throwaway venv, bandit -c pyproject.toml -r src tests:

  • Before this config: 93 B101 findings (48 in src/, 45 in tests/)
  • After: 48 -- identical to -r src alone. tests/'s contribution is fully suppressed, src/'s is unaffected.

🤖 Generated with Claude Code

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Bare `assert` is idiomatic pytest style (~45 test-suite uses), not a
security concern -- B101 exists to catch assert used for real validation
in src/ (asserts vanish under `python -O`), where it's still doing
legitimate work (48 findings there, unaffected by this change).

Verified with a throwaway venv: `bandit -c pyproject.toml -r src tests`
now reports the same 48 issues as `-r src` alone (was 93 combined before
this config), and `-r src` alone is unchanged.

Codacy's Python engine is Prospector, which wraps Bandit and honours this
native pyproject.toml config directly -- no Codacy-side setting needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@petercorke
petercorke force-pushed the fix/bandit-skip-assert-check-in-tests branch from 546f55a to e62b116 Compare August 17, 2026 07:43
@petercorke
petercorke merged commit 11781fe into main Aug 17, 2026
31 checks passed
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.

1 participant