是否有任何方法可以在pyproject.toml中设置要忽略的路径,例如
#pyproject.toml
[tool.pytest.ini_options]
ignore = ["path/to/test"]与其使用加注,不如:
#pyproject.toml
[tool.pytest.ini_options]
addopts = "--ignore=path/to/test" 发布于 2022-11-10 15:41:01
您可以在[tool.pytest.ini_options] (或pytest.ini)中添加的配置选项列表记录在https://docs.pytest.org/en/7.1.x/reference/reference.html#configuration-options中,其中包括addopts、norecursedirs等。到目前为止,还没有像ignore这样的测试发现选项可以在pytest.ini或pyproject.toml中列出。
但是,您有一些选择:
使用testpaths
https://docs.pytest.org/en/7.1.x/reference/reference.html#confval-testpaths
最好是维护一个白名单(包括列表)来运行测试,比如包或测试套件。这将设置应该搜索以进行测试发现的目录列表。
[tool.pytest.ini_options]
testpaths = your_package testing在collect_ignore中使用testconf.py
https://docs.pytest.org/en/7.1.x/example/pythoncollection.html#customizing-test-collection https://docs.pytest.org/en/7.1.x/reference/reference.html#global-variables
您可以在collect_ignore或connect_ignore_glob中添加全局变量conftest.py,以自定义收集测试时应该排除哪些文件/目录。这是更强大的,因为它允许动态的运行时值,而不是在pyproject.toml中。
# conftest.py
collect_ignore = ["path/to/test/excluded"]
collect_ignore_glob = ["*_ignore.py"]备注
顺便指出,norecursedirs可能用于排除某些子模块或子目录,但这不是一个好主意,因为这应该包含忽略某些构建工件或被忽略的目录的模式,例如_build、.venv、dist等。
发布于 2022-04-06 09:30:56
在pyproject.toml中使用以下内容
norecursedirs = [
"path/to/test/*",
]https://stackoverflow.com/questions/68287352
复制相似问题