Per-check skips in pyproject.toml causes test to be skipped across the whole project

Open
#1,478 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
security

Research direction

Start by tracing how Bandit reads [tool.bandit.assert_used] from pyproject.toml and applies its skips pattern during the bandit -c pyproject.toml -r click_async_plugins/ run. Add or locate a regression test using the reported tests/**.py pattern. Done means matching test files can use assert without findings while the assert in click_async_plugins/core.py is still reported.

Written by the indexing model from the issue text.

Description

bug
Describe the bug

It seems not possible to use pyproject.toml to skip certain tests for certain files.

Reproduction steps

I added assert True to a file for testing:

% bandit -c pyproject.toml -r click_async_plugins/
[…]
Test results:
>> Issue: [B101:assert_used] Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
   Severity: Low   Confidence: High
   CWE: CWE-703 (https://cwe.mitre.org/data/definitions/703.html)
   More Info: https://bandit.readthedocs.io/en/1.9.4/plugins/b101_assert_used.html
   Location: click_async_plugins/core.py:15:4
14	def cli_core(ctx: click.Context) -> None:
15	    assert True
16	    ctx.obj = CliContext(itc=ITC())
[…]

Since I want to be able to use assert in all files tests/**/*.py, I added to pyproject.toml:

[tool.bandit.assert_used]
skips = 'tests/**.py'

Now running Bandit will no longer identify the assert in click-async-plugins/core.py, despite that file not matching the glob.

% bandit -c pyproject.toml -r click_async_plugins/
[…]
Test results:
	No issues identified.
[…]
Expected behavior

I would expect this to work, obviously. Since it isn't, I was looking for documentation, but also could not find anything. And finally, not even --debug output provided an clues…

Bandit version

1.9.1 (Default)

Python version

3.14 (Default)

Additional context
% bandit --version
bandit 1.9.4
Dominant language
Python
Stars
8.4k
Forks
893
Avg merge
6h 52m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PyCQA/bandit

All issues in PyCQA/bandit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.