Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One-liner in bandit config to skip B101 assert_used in files matching a filter #346

Closed
mareecarroll opened this issue Jul 23, 2018 · 5 comments · Fixed by #633 or wilbertom/bandit#1
Labels
enhancement New feature or request
Milestone

Comments

@mareecarroll
Copy link

Currently you can exclude a directory and you can skip certain tests across all scanned files. It would be very handy to be able to exclude test_* pytest files from the B101 assert test with a simple one liner in the .bandit config file.

This is a feature request for something like:

In .bandit

[bandit]
pytest_filter: test_* #excludes B101 in files matching test_*

Excluding all B101 is not a good solution, because I want to know about B101 in non-test modules.

Also, I'd like to be able to exclude on file filter like test_* rather than directory test/ because that filter works better across projects I have seen where test directory might not be named consistently, but all the pytests are generally named a special way e.g. test_*

This will allow a more general (across projects) config file to be set up.

@ericwb ericwb added the enhancement New feature or request label Jul 23, 2018
aqw added a commit to pigskin/pigskin that referenced this issue Oct 2, 2018
This, unfortunately, skips the test for all files. Upstream has a feature
request for disabling tests for only certain files/folders.

PyCQA/bandit#346
@ericwb
Copy link
Member

ericwb commented May 9, 2019

Does #450 satisfy this feature request?

@ericwb ericwb added this to the Near Future milestone May 9, 2019
@cancan101
Copy link

@ericwb can you elaborate on how you would use #450 to exclude the use of asserts just in the test files?

@maxcountryman
Copy link

@ericwb I'd also be curious to know how #450 can be used to address this?

@loikein
Copy link

loikein commented Jun 24, 2020

Does this not work anymore?

wilbertom added a commit to wilbertom/bandit that referenced this issue Aug 12, 2020
Adding this configuration allows the user to skip the assert_used
against some files. This is useful because asserts are very common
in test files when using pytest.

Specifying this configuration:

```
assert_used:
  skips: ['test.py$', '^test']
```

would skip all asserts against a test file.

Resolves PyCQA#346
wilbertom added a commit to wilbertom/bandit that referenced this issue Nov 24, 2020
Adding this configuration allows the user to skip the assert_used
against some files. This is useful because asserts are very common
in test files when using pytest.

Specifying this configuration:

```
assert_used:
  skips: ['test.py$', '^test']
```

would skip all asserts against a test file.

Resolves PyCQA#346
wilbertom added a commit to wilbertom/bandit that referenced this issue Nov 25, 2020
Adding this configuration allows the user to skip the assert_used
against some files. This is useful because asserts are very common
in test files when using pytest.

Specifying this configuration:

```
assert_used:
  skips: ['*_test.py', 'test_*.py']
```

would skip all asserts against a test file.

Resolves PyCQA#346
lukehinds added a commit that referenced this issue Nov 30, 2020
* Add skip configuration to assert_used

Adding this configuration allows the user to skip the assert_used
against some files. This is useful because asserts are very common
in test files when using pytest.

Specifying this configuration:

```
assert_used:
  skips: ['*_test.py', 'test_*.py']
```

would skip all asserts against a test file.

Resolves #346

* Document assert test skipping

Co-authored-by: Luke Hinds <7058938+lukehinds@users.noreply.github.com>
@ericwb ericwb modified the milestones: Near Future, Release 1.6.3 Dec 6, 2020
mikespallino pushed a commit to mikespallino/bandit that referenced this issue Aug 25, 2021
* Add skip configuration to assert_used

Adding this configuration allows the user to skip the assert_used
against some files. This is useful because asserts are very common
in test files when using pytest.

Specifying this configuration:

```
assert_used:
  skips: ['*_test.py', 'test_*.py']
```

would skip all asserts against a test file.

Resolves PyCQA#346

* Document assert test skipping

Co-authored-by: Luke Hinds <7058938+lukehinds@users.noreply.github.com>
@diegovalenzuelaiturra
Copy link

diegovalenzuelaiturra commented Nov 16, 2021

Hi, the following may be helpful to configure bandit to avoid raising B101 assert_used warnings on python tests.

mikespallino pushed a commit to mikespallino/bandit that referenced this issue Jan 7, 2022
* Add skip configuration to assert_used

Adding this configuration allows the user to skip the assert_used
against some files. This is useful because asserts are very common
in test files when using pytest.

Specifying this configuration:

```
assert_used:
  skips: ['*_test.py', 'test_*.py']
```

would skip all asserts against a test file.

Resolves PyCQA#346

* Document assert test skipping

Co-authored-by: Luke Hinds <7058938+lukehinds@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
6 participants