如何在使用pytest-repeat时动态捕获测试内的迭代次数 [英] How to capture the iteration number dyanmically inside test while using pytest-repeat

查看:26
本文介绍了如何在使用pytest-repeat时动态捕获测试内的迭代次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用pytest-repeat多次执行我的Selenium脚本。我需要在执行期间捕获迭代编号并使用它。

我研究了pytest.mark、pytest.Collect&;pytest.Collector

class Testone():

 @pytest.fixture()

 def setup(self):

 @pytest.mark.repeat(RowCount)

 def test_create_eq(self,setup):

需要在此处捕获迭代编号。

推荐答案

我认为应该有比我下面描述的更简单、更直接的方法。pytest-repeat有一个灯具__pytest_repeat_step_number,我希望它可以提供测试的当前步骤号,但它没有。

request.node.name提供由pytest_repeat生成的测试函数的名称,并且它具有您可以提取的步骤编号。

import pytest

class Testone():

    @pytest.fixture()
    def setup(self):
        pass

    @pytest.mark.repeat(4)
    def test_create_eq(self,setup,request):
        current_step = request.node.name.split('[')[1].split('-')[0]  #string form; parse to int, if required

这篇关于如何在使用pytest-repeat时动态捕获测试内的迭代次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆