我想同时执行多个测试,但得到的是一个讨厌的图形。
pytest tests -k '1.1.18 or 4.1.12 or 6.1.11 or 6.1.12' ...
...
ERROR: Wrong expression passed to '-k': 1.1.18 or 4.1.12 or 6.1.11 or 6.1.12
pytest tests -k 1.1.18 ...
执行一个测试就可以了。 我的团队使用特定于操作系统发行版的套件文件来组织我们的测试,并将测试编号与脚本&方法关联起来,像这样。
tests:
- test_function: "foo.py:test_bar1"
test_id: "1.1.1.1"
- test_function: "foo.py:test_bar2"
test_id: "1.2"
...
我做错了什么?
第一个 pip install pytest-xdist
然后使用 pytest -n NUM
其中NUM是你想要并行运行的数量的整数。
所以要并行运行3个。
pytest -n3
或
pytest -n 3
文档链接。https:/docs.pytest.orgen3.0.1xdist.html。
编辑
-k
取测试函数名。你希望它们是唯一的。
tests:
- test_function1: "foo.py:test_bar1"
test_id: "1.1.1.1"
- test_function2: "foo.py:test_bar2"
test_id: "1.2"
...
pytest -k "test_function1 or test_function1"
注意在windows cmd中你必须使用 "
不 '