pytest实现多进程与多线程运行

1、pytest-parallel

  安装: pip install pytest-parallel

  常用参数配置:

  --workers=n:多进程运行需要加此参数,  n是进程数。默认为1

  --tests-per-worker=n:多线程需要添加此参数,n是线程数

  如果两个参数都配置了,就是进程并行,每个进程最多n个线程,总线程数:进程数*线程数

  注意:在windows上进程数永远为1。

     需要使用 if __name__ == "__main__":,在dos中运行会报错

  实现:

  

import pytest
def test_03(start,open_web1):
    print('测试用例3操作')
def test_04(start,open_web1):
    print('测试用例4操作')

if __name__ == "__main__":
    pytest.main(["-s", "test_1.py",'--workers=2', '--tests-per-worker=4'])

 

2、pytest-xdist

  安装:pip install pytest-xdist

  不支持多线程

  常用参数配置:

  -n=*:*代表进程数

  

注意:

    1、pytest-parallel加了多线程处理后,最后执行时间是运行时间最长的线程的时间。

    2、在windows下想用多进程的选pytst-xdist; 想用多线程的选pytest-parallel

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐