pytest特性记录:并发运行测试用例

关键字:-n

pytest运行参数 -n用于并发运行多个测试用例,该并发运行是进程级别的并发测试,使用前,需安装pytest-xdist插件。其中 -n=auto表示使用服务器所有的CPU来运行测试用例,举例如下:

import time
import pytest


class TestPytestFeatures(object):
    def test_case_login(self):
        time.sleep(1)
        num = 1
        assert num == 1

    def test_case_logout(self):
        time.sleep(1)
        tmp = ["a", "b"]
        assert isinstance(tmp, list)

    def test_case_shopping(self):
        time.sleep(1)
        tmp = ["a", "b"]
        assert isinstance(tmp, list)

    def test_case_walk(self):
        time.sleep(1)
        tmp = ["a", "b"]
        assert isinstance(tmp, list)


if __name__ == "__main__":
    pytest.main(["-n=2", "test_case_pytest_features.py"])

"""
运行结果
============================= test session starts =============================
platform win32 -- Python 3.8.7, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: E:\icp_capp\help
plugins: allure-pytest-2.9.43, forked-1.3.0, xdist-2.4.0
gw0 I / gw1 I
gw0 [4] / gw1 [4]

....                                                                     [100%]
============================== warnings summary ===============================
test_case_pytest_features.py:37
  E:\icp_capp\help\test_case_pytest_features.py:37: DeprecationWarning: invalid escape sequence \i


-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================== 4 passed, 1 warning in 2.51s =========================

Process finished with exit code 0

"""

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值