- 博客(4)
- 收藏
- 关注
原创 pytest的fixture使用方法
'''pytest的夹具(fixture)相比较unittest更强大,与unittest类似也是提供前后置1、setup_function、teardown_function、setup_method、teardown_method 函数级别前后置和类级别前后置2、pytest的fixture的包是放在conftest中,使用@pytest.fixture() 装饰器定义前置和后置,而且可以把前后置条件封装起来,将里面的一些参数给我们的测试用例使用,如果我们要用的时候直接调用就行了3、@pyte.
2022-05-29 16:00:13
377
原创 pytest数据驱动
import pytestcaselist=['item1','item2','item3']@pytest.mark.parametrize('info',caselist)def test_01(info): print(info)pytest数据驱动与ddt类似,使用装饰器@pytest.mark.parametrize,注意前面的里面的'info'需要带引号,否则就将他作为变量使用了,后面的就是我们的数据,list 字典格式等都是支持的运行结果如下:pytest.py::t.
2022-05-29 15:07:09
526
原创 Python 动态属性设置
1、设置属性 setattr(object,key,value),可以设置类属性和实例属性2、获取属性 getattr(object,key,"属性不存在的时候返回的值,避免报错")3、删除属性 delattr(object,key)4、属性检查是否存在 hasattr(object,key)class test(): name="jacky" def __init__(self): self.name="lebang"if __name__ == '__
2022-03-23 22:22:06
1663
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人