pytest中,收集测试用例、运行fixture函数、执行测试用例的顺序下,如何处理异常用例?

2026-05-24 19:000阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计1383个文字,预计阅读时间需要6分钟。

pytest中,收集测试用例、运行fixture函数、执行测试用例的顺序下,如何处理异常用例?

pytest执行顺序【收集测试用例、运行fixture函数、运行测试用例】+1、首先,pytest测试用例在执行之前,首先会收集测试套件中所有的测试用例。对于参数化的测试用例(即使用了参数化功能的测试用例),pytest会先执行这些测试用例。

pytest执行的顺序

1、首先,pytest测试用例在执行之前,首先先收集测试套件中所有的测试用例。

可以参考这篇博客

import pytest
from tools.read_config import *


class TestLogin1:
def test_1(self):
print(ReadConfig().read_config('project_GHelper', 'token'))

@pytest.mark.skip
def test_2(self):
print('用例执行2')


class TestLogin2:
@pytest.mark.parametrize('data1, data2', [(1, 2), ('a', 'b')], ids=['第一个测试用例', '第二个测试用例'])
def test_3(self, data1, data2):
print(data1, data2)

运行结果:

收集需要运行的测试用例时,用例参数化部分会提前运行,即需要收集所有的测试用例数量;然后才开始执行测试用例,即执行测试方法体里面的程序。

阅读全文

本文共计1383个文字,预计阅读时间需要6分钟。

pytest中,收集测试用例、运行fixture函数、执行测试用例的顺序下,如何处理异常用例?

pytest执行顺序【收集测试用例、运行fixture函数、运行测试用例】+1、首先,pytest测试用例在执行之前,首先会收集测试套件中所有的测试用例。对于参数化的测试用例(即使用了参数化功能的测试用例),pytest会先执行这些测试用例。

pytest执行的顺序

1、首先,pytest测试用例在执行之前,首先先收集测试套件中所有的测试用例。

可以参考这篇博客

import pytest
from tools.read_config import *


class TestLogin1:
def test_1(self):
print(ReadConfig().read_config('project_GHelper', 'token'))

@pytest.mark.skip
def test_2(self):
print('用例执行2')


class TestLogin2:
@pytest.mark.parametrize('data1, data2', [(1, 2), ('a', 'b')], ids=['第一个测试用例', '第二个测试用例'])
def test_3(self, data1, data2):
print(data1, data2)

运行结果:

收集需要运行的测试用例时,用例参数化部分会提前运行,即需要收集所有的测试用例数量;然后才开始执行测试用例,即执行测试方法体里面的程序。

阅读全文