zoukankan      html  css  js  c++  java
  • Pytest运行测试用例的多种方式

    #Below are test_pytest_markers.py 
    # content of test_server.py
    
    import pytest
    
    @pytest.mark.webtest
    
    def test_send_http():
    
    pass # perform some webtest test for your app
    
    def test_something_quick():
    
    pass
    
    def test_another():
    
    pass
    
    class TestClass:
    
    def test_method(self):
    
    pass

    1. Pytest Marker 机制

    对于Pytest的测试用例,可以在每一个测试用例加一个marker,比如pytest运行的时就只运行带有该marker的测试用例,比如下面的@pytest.mark.webtest。

    C:UsersPycharmProjectspytest_example>pytest -v -m "webtest" test_pytest_markers.py
    ============================= test session starts =============================
    platform win32 -- Python 2.7.13, pytest-3.0.6, py-1.4.32, pluggy-0.4.0 -- C:Python27python.exe
    cachedir: .cache
    rootdir: C:UsersPycharmProjectspytest_example, inifile:
    collected 4 items 
    
    test_pytest_markers.py::test_send_http PASSED
    
    ============================= 3 tests deselected ==============================
    =================== 1 passed, 3 deselected in 0.04 seconds ====================
      》》》》》pytest -v -m "not webtest" test_pytest_markers.py

    2. 选择运行特定的某个测试用例

    你可以按照某个测试用例的的模块,类或函数来选择你要运行的case,比如下面的方式就适合一开始在调试单个测试用例的时候。

    pytest -v test_pytest_markers.py::TestClass::test_method

    3. 选择运行特定的某个类

    >pytest -v test_pytest_markers.py::TestClass

    4 多种组合

    >pytest -v test_pytest_markers.py::TestClass test_pytest_markers.py::test_send_http

    5 用-k进行关键字匹配来运行测试用例名字子串

    >pytest -v -k http test_pytest_markers.py
  • 相关阅读:
    vivado操作基本问题
    IIC通信控制的AD5259------在调试过程中遇到的奇葩问题
    FPGA基础架构总结
    PLL到底是个啥么东西呢?
    CSS-3 Transform 的使用
    CSS-3 box-shadow 的使用
    一些CSS3的乐趣
    CSS-3 文字阴影—text-shadow 的使用
    Jquery 较好的效果
    如何关闭输入法
  • 原文地址:https://www.cnblogs.com/feiyi211/p/6625841.html
Copyright © 2011-2022 走看看