pytest框架(四)
2024-09-03 19:10:45
测试用例setup和teardown
代码示例一
# coding=utf-8
import pytest def setup_module():
print("setup_module:整个.py模块只执行一次")
print("比如:所有用例开始前只打开一次浏览器") def teardown_module():
print("teardown_module:整个.py模块只执行一次")
print("比如:所有用例结束只最后关闭浏览器") def setup_function():
print("setup_function:每个用例开始前都会执行") def teardown_function():
print("teardown_function:每个用例结束前都会执行") def test_one():
print("正在执行----test_one")
x = "this"
assert 'h' in x def test_two():
print("正在执行----test_two")
x = "hello"
assert hasattr(x, 'check') def test_three():
print("正在执行----test_three")
a = "hello"
b = "hello world"
assert a in b if __name__ == "__main__":
pytest.main(["-s", "test_fixt.py"])
代码示例二
# coding=utf-8 import pytest class TestClass:
def setup(self):
print("setup: 每个用例开始前执行") def teardown(self):
print("teardown: 每个用例结束后执行") def setup_class(self):
print("setup_class:所有用例执行之前") def teardown_class(self):
print("teardown_class:所有用例执行之前") def setup_method(self):
print("setup_method: 每个用例开始前执行") def teardown_method(self):
print("teardown_method: 每个用例结束后执行") def test_one(self):
x = "this"
assert 'h' in x def test_two(self):
x = "hello"
assert hasattr(x, 'check') def test_three(self):
a = "hello"
b = "hello world"
assert a in b if __name__ == "__main__":
pytest.main(['-q', 'test_class.py'])
最新文章
- CSS之viewport 2
- Mac OS 后台服务注册
- 【转】WordPress转PHPCMS策略-数据库完美转换
- 《day18_String练习_基本类型包装类_集合入门》
- Struts2笔记——struts.xml配置详解
- [iOS微博项目 - 2.0] - OAuth授权3步
- 【转】Android中引入第三方Jar包的方法(java.lang.NoClassDefFoundError解决办法)
- 资源文件(.RES)的应用
- C#语法糖演进-C#语言和.NET Framework平台介绍
- RMAN 备份异机恢复 并创建新DBID
- spring mvc跨域(post)--filter方案
- springboot问题总结
- C#访问MySQL数据库的方法
- linux内核中的IPIs是什么?
- Python基础(list和tuple)可变集合和‘不可变’集合
- 南阳理工大学oj 题目15 括号匹配(二)
- SSH Secure Shell Client--- the host may be dow
- spark cache table
- Linux 文件缓存 (二)
- strcpy unsigned char