Python 当pytest.ini位于tests子目录而不是项目根目录中时,pytest.ini中的pytest配置未注册
尽管按照pytest文档(请参阅)正确注册了测试套件,但pytest在运行我的测试套件时发出警告,原因是自定义标记未知 我的Python项目的结构是(为了这个查询而简化): 我的Python 当pytest.ini位于tests子目录而不是项目根目录中时,pytest.ini中的pytest配置未注册,python,pytest,Python,Pytest,尽管按照pytest文档(请参阅)正确注册了测试套件,但pytest在运行我的测试套件时发出警告,原因是自定义标记未知 我的Python项目的结构是(为了这个查询而简化): 我的pytest.ini是(再次简化): 因为我的conftest.py包含pytest文档中概述的@pytest.mark.incremental配方(请参阅) 当我从项目根目录(即/my_project/$pytest)中的命令行运行pytest时,pytest发出以下警告: PytestUnknownMarkWarni
pytest.ini
是(再次简化):
因为我的conftest.py
包含pytest文档中概述的@pytest.mark.incremental
配方(请参阅)
当我从项目根目录(即/my_project/$pytest
)中的命令行运行pytest时,pytest发出以下警告:
PytestUnknownMarkWarning: Unknown pytest.mark.incremental - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.incremental
-- Docs: https://docs.pytest.org/en/stable/warnings.html
但是,如果我告诉pytest运行tests目录(即/my_project/$pytest tests
),我不会收到这样的警告。类似地,如果我将我的pytest.ini
文件从tests目录中移回项目根目录,那么我也不会得到错误
有没有一种方法可以配置pytest,这样我就可以将我的结构保持为tests/pytest.ini
,以避免项目根目录过于混乱,同时还可以确保pytest在从命令行运行/my_project/$pytest
时正确读取我的pytest.ini
其他有用信息:
(my-project-env) /Users/me/Documents/my_project/ $ pytest
============================================= test session starts =============================================
platform darwin -- Python 3.8.5, pytest-6.0.2, py-1.9.0, pluggy-0.13.1
rootdir: /Users/me/Documents/my_project
PytestUnknownMarkWarning: Unknown pytest.mark.incremental - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.incremental
-- Docs: https://docs.pytest.org/en/stable/warnings.html
(my-project-env) /Users/me/Documents/my_project/ $ pytest
============================================= test session starts =============================================
platform darwin -- Python 3.8.5, pytest-6.0.2, py-1.9.0, pluggy-0.13.1
rootdir: /Users/me/Documents/my_project