Skip to content

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

Open
petercorke wants to merge 1 commit into
mainfrom
fix/bandit-skip-assert-check-in-tests
Open

fix: exclude tests/ from Bandit's assert_used (B101) check#99
petercorke wants to merge 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

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>
@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.

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