Repository navigation
fix: exclude the test directory from bandit - #4989
Merged
kddejong merged 1 commit intoNov 4, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4989 +/- ##
=======================================
Coverage 94.80% 94.80%
=======================================
Files 441 441
Lines 16165 16165
Branches 3135 3135
=======================================
Hits 15326 15326
Misses 463 463
Partials 376 376
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
This repo's test directory is
test/(singular), so the"tests"entry in[tool.bandit] exclude_dirshas never matched it and bandit has been scanning the whole test suite.bandit's exclusion is a bare substring test, not a path match — from
bandit/core/manager.py::_is_file_includedin 1.7.9 (the version pinned in.pre-commit-config.yaml):Because of that, the trailing slash matters:
"test"alone would also exclude anysrc/file whose path contains that substring (e.g. a futuresrc/cfnlint/.../testing_helper.py)."./test"does not work either, since pre-commit passes bare relative paths with no./prefix.Measured with
pre-commit run bandit --all-fileson this branch vsmain:src/is still scanned: adding_bandit_sanity = "/tmp/sanity"tosrc/cfnlint/helpers.pyfails B108 atsrc/cfnlint/helpers.py:869, and passes again once reverted./tmpstring in a tracked file undertest/fails B108 with the old config and passes with this one.This unblocks #4914, where two test fixtures containing
"cwd": "/tmp"fail CI on B108.Full local gate:
pytest test3445 passed / 0 failed,pre-commit run --all-filesall hooks pass.