这是我的 API 测试目录布局:
api_tests
├── conftest.py
└── query
└── me_test.py
conftest.py的内容:
print("CONFTEST LOADED")
me_test.py 的内容:
"""Tests the "me" query"""
def test_me():
assert True
如果我只是运行pytest,一切正常:
================================================= test session starts =================================================
platform linux -- Python 3.8.5, pytest-6.1.0, py-1.9.0, pluggy-0.13.1
rootdir: /home/hubro/myproject, configfile: pytest.ini
collecting ... CONFTEST LOADED
collected 3 items
api_tests/query/me_test.py . [ 33%]
lib/myproject/utils_test.py . [ 66%]
lib/myproject/schema/types/scalars_test.py .
注意打印“CONFTEST LOADED”。伟大的!然而,这个测试运行也获取了我不想要的所有单元测试。我想将我的测试运行分为单元测试和 API 测试,我不想一次性运行它们。
但是,如果我只是运行pytest api_tests/:
================================================= test session starts =================================================
platform linux -- Python 3.8.5, pytest-6.1.0, py-1.9.0, pluggy-0.13.1
rootdir: /home/hubro/myproject, configfile: pytest.ini
collected 1 item
api_tests/query/me_test.py . [100%]
================================================== 1 passed in 0.00s ==================================================
现在运行了正确的测试,但是 conftest.py 文件没有加载......这是怎么回事?
我在 Python 3.8 上使用 Pytest 6.1.0。
编辑:好吧,我找到了一个可接受的解决方法。我可以通过命令行使用该选项覆盖 INI 文件选项-o。这有效:
poetry run pytest -o "testpaths=api_tests"
然而,我非常想要原始问题的答案,所以我不会删除它。
慕姐8265434
相关分类