首页 > 其他分享 >Pytset使用教程

Pytset使用教程

时间:2022-12-02 00:22:41浏览次数:40  
标签:function 教程 Pytset fixfup print pytest 使用 test class

目录

测试类

import pytest

class TestLogin1():

	def test_case01(self,fixfup_function,fixfup_class):
		print("test_csae01")

	@pytest.mark.slow
	def test_case02(self,fixfup_function,fixfup_class):
		print("test_csae02")

	def test_case03(self,fixfup_function,fixfup_class):
		print("test_csae03")

	@pytest.mark.gxj
	def test_case04(self,fixfup_function,fixfup_class):
		print("test_csae04")

class TestLogin2():

	def test_case01(self,fixfup_function,fixfup_class):
		print("test_csae01")


	def test_case02(self,fixfup_function,fixfup_class):
		print("test_csae02")

	@pytest.mark.slow
	def test_case03(self,fixfup_function,fixfup_class):
		print("test_csae03")

	def test_case04(self,fixfup_function,fixfup_class):
		print("test_csae04")


	@pytest.mark.skip
	def test_case04(self,fixfup_function,fixfup_class):
		print("test_csae04")

前置后置类方法/函数方法

contest.py

import pytest

@pytest.fixture()
def fixfup_function():
	print("function前置")
	yield
	print("function后置")

#autouse=True
@pytest.fixture(scope="class",)
def fixfup_class():
	print("class前置")
	yield
	print("class后置")

数据驱动-参数化

class Test_case01():
	case = [
		{"case_id":1,"data":"123","expectesd":"200","title":'登陆成功'},
		{"case_id":2,"data": "123","expectesd":"200","title": '登陆失败'}
	]

	@pytest.mark.parametrize("item",case)
	def test_dmeo01(self,item):
		assert item["case_id"]==1000

用例标签

pytest.ini

[pytest]
markers =
    slow
    gxj

pytest收集用例执行

···
import pytest

pytest.main(["-s","-v"])

用例打标签运行

pytest.main(["-s","-v","-m","gxj or slow"])

生成pytset-html报告

pytest.main(["-s","-v","test_demo03.py","--html=reports/report.html"])

生成allure报告

1、下载allure报告https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
2、设置系统环境变量
3、执行生成报告文件:pytest.main(["-s","-v","test_demo03.py","--alluredir=reports/"])
4、allure runserve 报告路径

重运行机制 pip install pytest-rerunfailures

pytest.main(["-s","-v","test_demo03.py","--reruns","2","--reruns-delay","3","--alluredir=reports/"])
···

标签:function,教程,Pytset,fixfup,print,pytest,使用,test,class
From: https://www.cnblogs.com/gxj521test/p/16943226.html

相关文章