python+pytest 自动化测试框架

pytest框架作用

测试框架的作用是,帮助我们管理、执行测试用例、参数化、断言、生成测试报告等基础性工作

命名规则

Pytest单元测试中的类名和方法名必须是以test_开头或者_test结尾的,类名以Test开头,执行中只能找到test开头的类和方法

pytest的setup,setup_class和teardown,teardown_class函数

运行于测试方法的始末,即:运行一次测试函数会执行一次setup和teardown运行于测试方法的始末,但是不管有多少测试函数都只执行一次setup_class和teardown_class

调用语句

pytest.main([‘–html=./report.html’,’模块.py::类::test_a_001′])
运行指定模块指定类指定用例,冒号分割,并生成测试报告
pytest.main([‘-x’,’–html=./report.html’,’t12est000.py’])
-x出现一条测试用例失败就退出测试
-v: 丰富信息模式, 输出更详细的用例执行信息
-s:显示print内容
-q: 简化结果信息,不会显示每个用例的文件名

pytest的运行方式

.表示用例通过
F表示失败
E表示用例中存在异常
S表示用例被跳过

Pytst生成自带的html测试报告

import pytest

class TestClass(object):
    def setup(self):
        print("setup......start")
    def setup_class(self):
        print("setup_class.....start")
    def test001(self):
        a = 1
        assert a == 1
    def test002(self):
        d = 5
        assert d == 5
    def test003(self):
        e = 7
        assert e == 7
    def teardown(self):
        print("teardown.....end")
    def teardown_class(self):
        print("teardown_class.....end")

if __name__ == '__main__':
    pytest.main(["-vs","--html=./report.html", "test_pytest.py"])

python+pytest 自动化测试框架

python+pytest 自动化测试框架

python+pytest 自动化测试框架

Original: https://blog.csdn.net/m0_53427919/article/details/117324950
Author: 意柠
Title: python+pytest 自动化测试框架

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/774332/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球