pytest与unittest不一样的前后置setup,teardown

曾宝月

关注

阅读 67

2022-04-01

pytest:

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import pytest


class TestLogin:

	def setup_class(self):
		print("在每个类执行前的初始化工作,如创建日志对象,创建数据库链接")

	def setup(self):
		print("在执行用例之前初始化代码,如打开浏览器")

	def test_01_login(self):
		print("测试pytest")

	def test_02_login(self):
		print("测试pytest")

	def test_03_login(self):
		print("测试pytest")

	def test_04_login(self):
		print("测试pytest")
	def teardown(self):
		print("在执行用例后执行扫尾代码,如关闭浏览器")

	def teardown_class(self):
		print("在每个类执行之后的扫尾工作,如销毁日志对象,销毁数据库链接")

pytest的都是小写

精彩评论(0)

0 0 举报