我正在使用 bandit 检查我的代码是否存在潜在的安全问题:
bandit -r git-repository/
然而,bandit 发现的最常见的项目是 B101 .它由测试中的断言语句触发。我使用 pytest,所以这不是一个问题,而是一个很好的做法。我现在创建了一个 .bandit
文件与[bandit]
skips: B101
但这也跳过了很多其他代码。这个问题有解决方案吗?
最佳答案
我使用的解决方案是告诉 bandit
完全跳过测试:
bandit --configfile bandit.yaml
与以下 bandit.yaml
在项目的根目录# Do not check paths including `/tests/`:
# they use `assert`, leading to B101 false positives.
exclude_dirs:
- '/tests/'
有一个bunch的 related issues和 pull requests .
关于python - 如何让老虎机在测试中跳过 B101?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63829128/