zoukankan      html  css  js  c++  java
  • pytest笔记-基本使用实践1

    import pytest

    def deb(x,y):
    return print("和:",x + y)

    def dec(x):
    return x + 1

    @pytest.mark.xfail(reason="标记失败的用例")
    @pytest.mark.web
    def test_01():
    assert dec(3) == 4

    def test_02():
    assert dec(4) == 5

    def test_03():
    assert dec(3) == 3

    @pytest.mark.skip(reason="跳过测试")
    @pytest.mark.web
    def test_04():
    assert dec(3) == 4

    @pytest.mark.app
    def test_05():
    print("test_05")
    assert dec(2) == 3

    def test_06():
    return True

    def test_07():
    if not test_06:
    pytest.mark.skipif("test skipif")

    @pytest.mark.parametrize("t1",[1,2,3])
    @pytest.mark.parametrize("t2",[2,3,4])
    def test_08(t1,t2):

    return deb(t1,t2)
    

    class TestApp:
    def test_09(self):
    return dec(3) == 4

    # 1.执行当前模块所以用例
    # pytest.main(["-s","test_main.py])
    #
    # 2.
    # pytest xx.py
    # 4.
    # ptest -x    # 第一次失败就停止
    # pytest --maxfail=2      #出现2次失败就停止
    #
    # 5.关键字执行
    # pytest -k "xx"
    # pytest -k "xx and not yy"
    #
    # 6.指定模块类中的方法
    # pytest test_main.py::TestApp::test_09
    #
    # 7.指定标签执行
    # pytest -m web
    

    if name == 'main':

    pytest.main(["test_main.py::test_02","-vs"])

    pytest.main(["test_main.py","-vs","-m","03"])

    执行方式: python xx.py

  • 相关阅读:
    sqlhelper类
    嵌入式的n个方向
    study vim + cscope
    mail lists
    关于我的学习
    yahoo enter linux mobile competition
    找工作啦 啦啦啦啦啦
    minicom display unsolicited codes
    并购的年代
    配置rt73无线网卡至suse10.3
  • 原文地址:https://www.cnblogs.com/cpas-3-org/p/15153860.html
Copyright © 2011-2022 走看看