测试用例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'])

最新文章

  1. CSS之viewport 2
  2. Mac OS 后台服务注册
  3. 【转】WordPress转PHPCMS策略-数据库完美转换
  4. 《day18_String练习_基本类型包装类_集合入门》
  5. Struts2笔记——struts.xml配置详解
  6. [iOS微博项目 - 2.0] - OAuth授权3步
  7. 【转】Android中引入第三方Jar包的方法(java.lang.NoClassDefFoundError解决办法)
  8. 资源文件(.RES)的应用
  9. C#语法糖演进-C#语言和.NET Framework平台介绍
  10. RMAN 备份异机恢复 并创建新DBID
  11. spring mvc跨域(post)--filter方案
  12. springboot问题总结
  13. C#访问MySQL数据库的方法
  14. linux内核中的IPIs是什么?
  15. Python基础(list和tuple)可变集合和‘不可变’集合
  16. 南阳理工大学oj 题目15 括号匹配(二)
  17. SSH Secure Shell Client--- the host may be dow
  18. spark cache table
  19. Linux 文件缓存 (二)
  20. strcpy unsigned char

热门文章

  1. 模拟登陆,selenium,线程池
  2. 5.1 《锋利的jQuery》jQuery对表单的操作
  3. c# CODE REVIEW (13-11 TO 14-01)
  4. SDUT OJ 螺旋矩阵
  5. nodejs socket.io初探
  6. Promise 入门与使用
  7. PHP 正则表达示
  8. 【LeetCode】070. Climbing Stairs
  9. break、continue和return的区别
  10. Linux的学习思路