sor*_*rin 65 python unit-testing pytest
我试图使用norecursedirssetup.cfg中的选项告诉py.test不要从某些目录中收集测试,但它似乎确实忽略了它.
[tool:pytest]
norecursedirs=lib/third
Run Code Online (Sandbox Code Playgroud)
当我跑步时,py.test我确实看到它是如何从内部进行测试的lib/third!
sha*_*dfc 57
py.test --ignore=somedir 为我工作
sor*_*rin 21
我解开了这个谜团:如果在其中一个可能的配置文件(pytest.ini,tox.ini和setup.cfg)中找到pytest部分,pytest将不会查找任何其他部分,因此请确保在单个文件中定义py.test选项.
我建议使用setup.cfg.
blu*_*e10 13
就我而言,问题是缺少通配符。以下对我有用:
[tool:pytest]
norecursedirs = subpath/*
Run Code Online (Sandbox Code Playgroud)
而只是norecursedirs = subpath没有。
Dav*_*sta 10
如果您有多个具有不同父级的目录,则可以指定不同的--ignore参数:
py.test --ignore=somedir --ignore=otherdir --ignore=etcdir
- 新选项:--ignore将阻止收集指定的路径。
可以多次指定。
如果您使用 setup.cfg,则必须[tool:pytest]按照http://doc.pytest.org/en/latest/example/pythoncollection.html使用
# pytest.ini 的内容
也可以在 tox.ini 或 setup.cfg 文件中定义,尽管
setup.cfg 文件中的部分名称应为“tool:pytest”
要使用pytest.ini(推荐使用,除非您tox在这种情况下使用tox.ini才有意义),请pytest使用pytest -c pytest.ini.
为了防止我的样品not_me_1.py被not_me_2.py测试或被检查,我pytest.ini的如下:
[pytest]
addopts = --ignore-glob=not_me_*
[pycodestyle]
ignore = not_me_* ALL
Run Code Online (Sandbox Code Playgroud)