zoukankan      html  css  js  c++  java
  • 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 ========================================================

  • 相关阅读:
    A02 React+Antdesign 创建新项目
    B02 Vue+Element 创建新项目
    B01 Vue+Element 开发环境搭建
    A01 React+Antdesign 开发环境准备
    批量处理TXT转csv
    pyinstall python文件打包成二进制exe文件
    vue前端与django后端数据交互
    页面自适应
    ETL-kettle通过java代码传递参数,调用job调用转换
    ETL-kettle基本操作,表的输入输出
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12219250.html
Copyright © 2011-2022 走看看