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)
  • 相关阅读:
    Ajax基础1
    jQuery框架源码解读
    关于struts、spring 和 hibernate的说明
    struts2学习笔记(一)
    NodeJS+MongoDB
    最佳实践(二)
    ajax请求web容器控制超时
    实战经验
    javascript学习笔记(二)
    spring学习笔记(六)
  • 原文地址:https://www.cnblogs.com/Teachertao/p/11902104.html
Copyright © 2011-2022 走看看