Python Pytest 忽略 setup.cfg 文件中提到的目录中的测试

Python Pytest ignore tests from a directory mentioned in the setup.cfg file

我正在尝试使用 pytest 运行 一些测试。我的包裹包含一个 setup.cfg 文件,我在其中说明了所有 pytest 选项

[tool:pytest] addopts = --verbose unit 因为它是可见的,所以我添加了 unit 目录来查找测试文件。这工作正常,目录中的所有测试都在正常构建过程中执行。

实际问题 -

现在我有另一个目录 integ,其中有我的集成测试,有时我想 运行 但不希望它们成为我构建过程的一部分。我已经为 运行 我的集成测试创建了另一个命令行选项,但我无法弄清楚如何为相同的

正确提供文件集

我已经尝试 pytest --ignore=unit integ 通过命令行,但它 运行 是我所有来自单元和集成的测试。我只想运行 integ 中存在的测试并忽略单元中的测试。我在这里错过了什么?

[更新] 当我 运行 pytest --ignore=unit/test_file.py integ 它忽略 test_file 中的测试但是当我使用 pytest --ignore=unit/*.py integ 它说 no matches found: --ignore=test/*.py

谢谢

--override-ini=testpaths=test_integ 解决了我的问题。我可以使用它覆盖 setup.cfg 文件中的选项。