pytest多进程执行测试用例
创建待测用例
import time
import pytest
def test_01():
print("test 1 begin")
assert 1==1
time.sleep(6)
print("test 1 begin")
def test_02():
print("test 2 begin")
time.sleep(6)
print("test 2 finish")
assert 0 == 1
print("test 2 assert")
调用pytest多进程执行测试用例
if __name__=="__main__":
pytest.main(['test_pytest.py','-n=auto'])
-n=auto根据cpu核心数选择进程数,使用此功能需要安装pytest-xdist
执行结果
============================= test session starts ===========================