zoukankan      html  css  js  c++  java
  • python + pytest基本使用方法(拓展库)

    一、测试钩子配置文件

    import pytest
    # conftest.py 是pytest特有的本地测试配置文件;
    # 既可以用来设置项目级别的Fixture,也可用来导入外部插件,还可以指定钩子函数

    #设置测试钩子

    @pytest.fixture()
    def test_url():
    return 'http://www.baidu.com'

    二、测试失败用例进行连跑
    # pip install pytest-rerunfailures
    # pytest-rerunfailures 可以在测试用例失败时进行重试(连跑)

    #通过 ‘--reruns’参数设置测试用例运行失败后的重试次数
    #执行 pytest -v test_rerunfailures.py --reruns 3

    def test_fail_rerun():
    assert 2 + 2 == 5

    三、测试线程数
    from time import sleep

    # pip install pytest-parallel
    # pytest-parallel 扩展可以实现测试用例的并行运行

    # 不使用线程运行测试用例
    # pytest -q test_parallel.py

    # 参数‘--tests-per-worker’用来指定线程数,auto 表自动分配
    #pytest -q test_parallel.py --tests-per-worker auto

    def test_01():
    sleep(3)

    def test_02():
    sleep(3)

    def test_03():
    sleep(6)
  • 相关阅读:
    Desert King
    Dropping tests
    01分数规划小结
    简单的数学题
    [HAOI2016]放棋子
    [SDOI2017]数字表格
    诸侯放置
    LJJ爱数数
    车的放置
    [SDOI2014]数表
  • 原文地址:https://www.cnblogs.com/Teachertao/p/11902104.html
Copyright © 2011-2022 走看看