[英]Can't make pytest dependency work for different modules
Following this answer and the doc , I am trying to make tests depend on each other between files:按照这个答案和 文档,我试图让测试在文件之间相互依赖:
test_connectivity.py
: test_connectivity.py
:
@pytest.mark.dependency(depends=["test_services_up.py::test_sssss"], scope="session")
def test_aaa():
assert False
@pytest.mark.dependency(depends=["tests/test_services_up.py::test_sssss"], scope="session")
def test_bbb():
assert False
@pytest.mark.dependency(depends=["atp/tests/test_services_up.py::test_sssss"], scope="session")
def test_ccc():
assert False
and test_services_up.py
:和test_services_up.py
:
@pytest.mark.dependency()
def test_sssss():
assert True
The folder structure:文件夹结构:
atp
----|tests
--------|test_connectivity.py
--------|test_services_up.py
Output: Output:
> ssh://me@host:port~/src/uv-fleet-atp/venv/bin/python -u ~/.pycharm_helpers/pycharm/_jb_pytest_runner.py --path ~/src/uv-fleet-atp/atp/tests
============================= test session starts ==============================
collected 4 items
test_connectivity.py::test_aaa SKIPPED (test_aaa depends on test_ser...)
Skipped: test_aaa depends on test_services_up.py::test_sssss
test_connectivity.py::test_bbb SKIPPED (test_bbb depends on tests/te...)
Skipped: test_bbb depends on tests/test_services_up.py::test_sssss
test_connectivity.py::test_ccc SKIPPED (test_ccc depends on atp/test...)
Skipped: test_ccc depends on atp/tests/test_services_up.py::test_sssss
test_services_up.py::test_sssss PASSED
========================= 1 passed, 3 skipped in 0.35s =========================
How to not skip dependent tests?如何不跳过相关测试?
As mentioned in the comments, pytest-dependency
does not order tests, it relies on the tests executed in the correct order for dependencies to work.正如评论中提到的, pytest-dependency
不对测试进行排序,它依赖于以正确顺序执行的测试以使依赖项起作用。 The reasoning behind this is that pytest-dependency
is thought to do one thing and one thing only, which is to skip tests depending on the test relationships.这背后的原因是pytest-dependency
被认为只做一件事,也就是根据测试关系跳过测试。 Ordering can either be done manually by arranging the tests accordingly (eg adapt the names, what most users seem to do), or rely on an ordering plugin.排序可以通过相应地安排测试来手动完成(例如,调整名称,大多数用户似乎都这样做),或者依赖于排序插件。 There has been a controversial discussion about this, and certainly not everyone agrees with that philosophy (I tend to agree), but in the end it is the prerogative of the plugin author to decide.对此有过争议性的讨论,当然不是每个人都同意这种理念(我倾向于同意),但最终决定权在插件作者手中。
pytest-order works together with pytest-dependency
. pytest-order与pytest-dependency
一起工作。 If it is installed and you run your tests with the option --order-dependencies it will order your tests with dependency
markers if needed.如果它已安装并且您使用选项--order-dependencies运行测试,它将在需要时使用dependency
标记对您的测试进行排序。 As usual, you can instead add the option to pytest.ini
:像往常一样,您可以将选项添加到pytest.ini
:
[pytest]
; always order tests with dependency markers
addopts = --order-dependencies
As for tests that cannot be found, it should issue a respective warning.对于找不到的测试,应分别发出警告。
Disclaimer:免责声明:
I'm the maintainer of pytest-order
.我是pytest-order
的维护者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.