zoukankan      html  css  js  c++  java
  • pytest扫盲2--pytest.main()

    直接上代码吧~~~~

    # File  : test_demo_2.py
    # IDE   : PyCharm
    
    import pytest
    
    def setup_function():
        print('*' * 10 +'用例开始!'+ '*' * 10)
    
    def teardown_function():
        print('*' * 10 +'用例结束!' + '*' * 10)
    
    def test_1():
        print('*' * 5 + 'test_1' + '*' * 5)
        a = 'hello world!'
        assert 'hello' in a
    
    def test_2():
        print('*' * 5 + 'test_2' + '*' * 5)
        x = 'hello world!'
        assert hasattr(x, 'helloWorld')
    
    @pytest.mark.smoke
    def test_3():
        print('*' * 5 + 'test_3' + '*' * 5)
        b = 3
        assert b == 4
    # File  : main.py
    # IDE   : PyCharm
    
    import pytest
    
    ## 1)不带参数执行用例:执行当前目录下所有测试用例
    # pytest.main()
    
    ## 2)指定文件名:执行该文件中的测试用例
    # pytest.main(['test_demo_2.py'])
    
    ## 3)指定参数和路径:pytest.main(['parameter', 'file.py'])
    ## parameter提供如下参数:
    '''
        1:'-s': 关闭捕捉,显示程序中的print/logging输出。
        2:'-v': 丰富信息模式, 输出更详细的用例执行信息。
        3:'-m=xxx': 运行打标签的测试用例。
        4:'q':  安静模式, 不输出环境信息。
        5:'-x': 出现一条测试用例失败就退出测试。
        6:'--maxfail=x':当用例执行失败次数达到x次后,退出测试
        7:'--resultlog=./log.txt' 生成log
        8:'--junitxml=./result.xml' 生成xml报告
        9:'--html=./result.html' 生成html报告
    '''
    # pytest.main(['-m=smoke', 'test_demo_2.py'])   # 运行标签为 smoke 的用例
    # pytest.main(['--maxfail=2', 'test_demo_2.py'])
    
    ## 4)指定目录:执行目录及子包的所有用例
    # pytest.main(['pytest_basic'])
    
    ## 5)指定类:
    # pytest.main(['test_demo_1.py::TestMethod'])
    
    ## 6)指定函数(函数名不需要带括号):
    pytest.main(['test_demo_1.py::test_my_func'])
    
    ## 7)指定类下的方法
    pytest.main(['test_demo_1.py::TestMethod::test_1'])
    喜时之言,多失信;怒时之言,多失体
  • 相关阅读:
    php字符串常用函数
    调试心得总结
    搜索查询简单的网页摘要生成
    OFFICE三线表的制作
    阶段性总结20130613
    url查重bloom过滤器
    Linuxvim常用命令
    不打开文件操作db时,如果遇到和窗体交互,不会提示文档未锁,但同样需要锁定当前文档,代码如下
    样条曲线
    不用遍历得到btr中同一类型的实体 CAD2009 vs2008及以上
  • 原文地址:https://www.cnblogs.com/xiaohuboke/p/13516843.html
Copyright © 2011-2022 走看看