我们已经使用 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
我为此创建了一个 pytest 插件:https://github.com/detachhead/pytest-robotframework