• pytest配置文件:


    目录结构:

    pytest.ini

    [pytest]
    addopts = -s -v
    testpaths = ./scripts
    python_files = test_*.py
    python_classes = Test*
    python_functions = test_*

    test_case.py

    def test_case_01():
    assert 1

    class TestCase(object):
    def test_case_01(self):
    """再执行三"""
    assert 1

    def test_case_02(self):
    """再执行六"""
    assert {"title":"v2ex"} != {"title":"V2EX"}

    def test_case_03(self):
    """再执行九"""
    assert 1

    def setup_class(self):
    """先执行一setup_class 类级别的setup"""
    print("类级别的setup")

    def teardown_class(self):
    """再执行十一teardown_class 类级别的teardown"""
    print("类级别的teardown")

    def setup_method(self):
    """再执行二setup_method 类中方法级别的setup"""
    """再执行五setup_method 类中方法级别的setup"""
    """再执行八setup_method 类中方法级别的setup"""
    print("类中方法级别的setup")

    def teardown_method(self):
    """再执行四teardown_method 类中方法级别的teardown"""
    """再执行七teardown_method 类中方法级别的teardown"""
    """再执行十teardown_method 类中方法级别的teardown"""
    print("类中方法级别的teardown ")

    test_login.py

    def test_login1():
    assert 0

    def test_login2():
    assert 1

    结果:

    =========================================================== test session starts ============================================================
    platform win32 -- Python 3.6.6, pytest-5.3.2, py-1.8.1, pluggy-0.13.1 -- c:python36python.exe
    cachedir: .pytest_cache
    rootdir: D:s27day68, inifile: pytest.ini, testpaths: ./scripts
    collected 6 items

    scripts/test_case.py::test_case_01 PASSED
    scripts/test_case.py::TestCase::test_case_01 类级别的setup
    类中方法级别的setup
    PASSED类中方法级别的teardown

    scripts/test_case.py::TestCase::test_case_02 类中方法级别的setup
    PASSED类中方法级别的teardown

    scripts/test_case.py::TestCase::test_case_03 类中方法级别的setup
    PASSED类中方法级别的teardown
    类级别的teardown

    scripts/test_login.py::test_login1 FAILED
    scripts/test_login.py::test_login2 PASSED

    ================================================================= FAILURES =================================================================
    _______________________________________________________________ test_login1 ________________________________________________________________

    def test_login1():
    > assert 0
    E assert 0

    scripts est_login.py:4: AssertionError
    ======================================================= 1 failed, 5 passed in 0.14s ========================================================

  • 相关阅读:
    初级模拟电路:8-1 运算放大器概述
    初级模拟电路:6-1 FET概述
    初级模拟电路:5-5 甲乙类功率放大器
    初级模拟电路:5-4 乙类功率放大器
    初级模拟电路:5-3 变压器耦合型甲类功放
    初级模拟电路:5-2 串馈型甲类功放
    μC/OS-II系统中事件标志的使用
    STM32-SPI读写外部FLASH(W25Q64)
    STM32-定时器输出比较模式输出方波(DMA方式)
    STM32-定时器输出比较模式输出方波(中断方式)
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12219250.html
Copyright © 2020-2023  润新知