Reputation: 29
I have one test suite with multiple subsuites. There are one or more test cases in each subsuite. For example:
TestSuite
Subsuite-1
TestCase-1
TestCase-2
Subsuite-2
TestCase-1
Subsuite-3
TestCase-1
TestCase-2
TestCase-3
So far I've been using this code with separate classes for suite and test case results:
from robot.api import ExecutionResult, ResultVisitor
class GetRfSuiteResults(ResultVisitor):
suite_results = {}
def visit_suite(self, suite):
self.suite_results[suite.name] = suite.status
class GetRfTestResults(ResultVisitor):
test_results = {}
def visit_test(self, test):
self.test_results[test.parent,test.name] = test.status
As they both inherit the same ResultVisitor
is it possible to get the results using one class like this?
from robot.api import ExecutionResult, ResultVisitor
class GetRfResults(ResultVisitor):
suite_results = {}
test_results = {}
def visit_suite(self, suite):
self.suite_results[suite.name] = suite.status
def visit_test(self, test):
self.test_results[test.parent,test.name] = test.status
I can't figure out how to access visit_test
in this solution.
Upvotes: 0
Views: 1575
Reputation: 7271
Although it mentions SuiteVisitor
and not ResultVisitor
I would venture with a guess that it behaves the same. From the API doc:
Visitors extending the SuiteVisitor can stop visiting at a certain level either by overriding suitable visit_x() method or by returning an explicit False from any start_x() method.
So if you override visit_suite
it will stop visiting there.
If you would like to have one ResultVisitor
that fetches the suite and test statuses as well, you could try something like this:
class MyResultVisitor(ResultVisitor):
def __init__(self):
self.suite_results = {}
self.test_results = {}
def visit_suite(self, suite):
self.suite_results[suite.name] = suite.status
for test in suite.tests:
self.test_results[test.parent,test.name] = test.status
for suite in suite.suites:
self.visit_suite(suite)
return False
Visiting only the top suite, you could recursively visit all child suites and their tests as well.
Upvotes: 3