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 ========================================================

  • 相关阅读:
    Linux shell 获取当前时间之前N天
    python 连接oracle 数据库
    Python 连接mysql
    python字符串反转
    java基础之数据类型转换
    java 基础之数据类型
    使用sublime编辑器编辑eclpse跑tomcat的项目不及时更新问题的解决方法
    日常git命令
    快速排序,按某个属性,或按“获取排序依据的函数”,来排序
    Gulp初识
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12219250.html
Copyright © 2011-2022 走看看