pytest - pytest:一次执行多个测试
问题描述
我想一次执行多个测试,但得到一个 nastygram:
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.org/en/3.0.1/xdist.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 中你必须使用"
not'
推荐阅读
- visual-studio-code - How to disable comment formatting in VS Code?
- python - 如何使用 Python Instaloader 跳过 Instagram Web 检查点
- mariadb - 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册以获取正确的语法 SQL MOCK SBA 分配
- ethers.js - 如何在 ethers.js ABI 中定义一个结构数组返回类型
- javascript - 日期字段在 pagedlist 的第二页上失去价值
- java - 在 Java 中查询距 AWS DynamoDB 10 英里内的最近位置
- jquery - 如何从模态插入更新值