Python 如何在Robot框架中获得测试用例列表而不启动实际测试?

Python 如何在Robot框架中获得测试用例列表而不启动实际测试?,python,robotframework,Python,Robotframework,我有文件test.robot和测试用例 如何在不激活测试的情况下从命令行或python获取此测试用例的列表?您可以查看。正如文档中所解释的,“创建的文档是HTML格式的,它包括每个测试套件和测试用例的名称、文档和其他元数据”。Robot测试套件很容易用Robot解析器解析: from robot.parsing.model import TestData suite = TestData(parent=None, source=path_to_test_suite) for testcase i

我有文件test.robot和测试用例


如何在不激活测试的情况下从命令行或python获取此测试用例的列表?

您可以查看。正如文档中所解释的,“创建的文档是HTML格式的,它包括每个测试套件和测试用例的名称、文档和其他元数据”。

Robot测试套件很容易用Robot解析器解析:

from robot.parsing.model import TestData
suite = TestData(parent=None, source=path_to_test_suite)
for testcase in suite.testcase_table:
    print(testcase.name)

对于v3.2及以上版本:

在RobotFramework 3.2中,Bryan Oakley的答案将不再适用于这些版本

与3.2之前和3.2之后版本兼容的适当代码如下:

from robot.running import TestSuiteBuilder
from robot.model import SuiteVisitor


class TestCasesFinder(SuiteVisitor):
    def __init__(self):
        self.tests = []

    def visit_test(self, test):
        self.tests.append(test)


builder = TestSuiteBuilder()
testsuite = builder.build('testsuite/')
finder = TestCasesFinder()
testsuite.visit(finder)

print(*finder.tests)
进一步阅读:


从您的上面导入测试数据时出错module@LinhNhatNguyen看看我的答案。