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

  • 相关阅读:
    父容器的flowover:hidden 必须配合父容器的宽高height width才能生效
    css使 同一行内的 文字和图片 垂直居中对齐?
    vim查找替换
    要让div中的float不会自动显示到下一行来?
    如何理解clear的css属性?
    div+css使多行文字垂直居中?
    VMnet1和V8
    unslider的用法详解
    json的中括号和大括号的使用?
    如何合理定价,定价定天下,必须要学会这个哦!
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12219250.html
Copyright © 2011-2022 走看看