如何使用机器人框架运行pytest测试用例?

问题描述 投票:0回答:1

我们已经使用 pytest 功能自动化了测试用例,但现在我们必须使用 Robot 框架来报告和运行测试用例。是否可以使用机器人运行 pytest 测试用例。

Py测试文件:test_sample.py

import pytest

@pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("2+4", 24), ("6*9", 54)])
def test_eval(test_input, expected):
        print(test_input, expected)
        assert eval(test_input) == expected

机器人文件将调用的执行文件。

exec.py

import os
import sys

def run_test_cases_of(sample_Test):
    os.system("pytest -s -v test_sample.py" )
Robot file which is runner: 


 ******settings ***
 Library  test_sample.py
 Library  exec.py


 ****Test Cases ***

 Running test case

    #test eval # When running through this robot is asking for argument
    run test cases of   sample_test #When throygh this robot understaing there is only one test case
python automation robotframework pytest
1个回答
0
投票

我为此创建了一个 pytest 插件:https://github.com/detachhead/pytest-robotframework

参数化测试在报告中显示为单独的测试,如下所示 like so

© www.soinside.com 2019 - 2024. All rights reserved.