#test_pytest
#pytest是一种自动化测试框架,是python的第三方单元测试框架,向下兼容unittest
#预期结果,实际结果
#pip install pytest,或者使用豆瓣源,清华源等进行安装
#pytest命名规范
#文件名应当以test_开头,或者以_test结尾
#类应当以Test开头,且类当中不能有__init__方法
#方法或函数应当以test_开头
#断言必须使用assert 结果为真,断言不做事情,结果为假,断言生效,抛出异常AssertionError
assert 1==2 #判断等式两边是否相等
assert 200 #判断某个语句是否为真
assert 10 in [10,20] #判断某个值是否属于某个对象
assert 1!=2 #判断某个值是否不等于另一个值
assert not False
import pytest
import allure
import os #加载系统模块
def test_01():
print('HelloWorld')
assert 1==1 #判断预期结果和实际结果是否一致
def test_02():
assert 1==2
@pytest.fixture(scope='class') #装饰器,相当于setup_method,缺省为method级别
#scope='module'
#scope='session',把fixture内容写到conftest.py里,目录下所有文件共用这个配置
def some_data():
print('开始')
yield #这句话以下的内容视为teardown_method
print('结束')
class Test1:
def teardown_method(self): #④
print('这是最后执行的方法')
def test_
pytest框架、allure报告框架的简单使用,数据驱动、setup和teardown装饰器、allure的层级
最新推荐文章于 2024-06-24 20:55:22 发布