python - 如何让老虎机在测试中跳过 B101?

标签 python bandit-python

我正在使用 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/'
有一个bunchrelated issuespull requests .

关于python - 如何让老虎机在测试中跳过 B101?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63829128/

相关文章:

python - Google Drive API 和服务帐户

python - 优达学城 CS101 : Not sure if this nested dictionary question is wrong or I'm missing something

python - Conda 命令(>> conda info --envs)现在在更改 .condarc 后显示所有环境两次

python输入提示字符串长度

python - 忽略/跳过 python bandit 安全问题报告中的某些问题的方法是什么?

使用 Bandit 进行安全分析的 Python 代码

python - SonarQube 不显示 Bandit 的 Python 安全漏洞报告

python - 分割字符串的每个字符的分隔符?