Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support testsuite in testsuite #152

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions testbase/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,15 @@ def _load_from_testsuite(
ignore_testsuite=True,
)
else:
tests += self._load_from_class(
test, data_key, exclude_data_key=exclude_data_key, attrs=attrs
)
if issubclass(test, TestSuite):
testcases = self._load_from_testsuite(
test, data_key, exclude_data_key=exclude_data_key, attrs=attrs
)
tests += [test(testcases)]
else:
tests += self._load_from_class(
test, data_key, exclude_data_key=exclude_data_key, attrs=attrs
)

return [it for it in tests if not cls.filter(it)]

Expand Down
28 changes: 25 additions & 3 deletions testbase/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,16 @@ def _log_testsuite_error(self, testsuite, testresult, message):

def _run_test(self, testsuite, test, testresult_factory, testresult):
"""执行测试用例"""
testresult.begin_step(test.test_name)
step_name = test.test_name
if isinstance(test, TestSuite):
step_name = "【%s】(%s)" % (step_name, test.exec_mode)
if testsuite.root_test_result and testsuite.root_test_result != testresult:
testsuite.root_test_result.begin_step(step_name)
testresult.begin_step(step_name)
testsuite.current_stage = test.test_name
runner = getattr(test, "case_runner", TestCaseRunner())
if isinstance(test, TestSuite):
test.root_test_result = testsuite.root_test_result
case_result = runner.run(test, testresult_factory)
if not case_result.passed:
self._log_testsuite_error(
Expand Down Expand Up @@ -316,9 +323,13 @@ def run(self, testsuite, testresult_factory):
raise ValueError("Invalid testsuite type: %s" % type(testsuite))
testresult = testresult_factory.create(testsuite)
testresult.begin_test(testsuite)
testresult.begin_step("pre_test")
if testsuite.root_test_result and testsuite.root_test_result != testresult:
testsuite.root_test_result.begin_step("【%s】 - pre_test" % testsuite.__class__.__name__)
testresult.begin_step("【%s】 - pre_test" % testsuite.__class__.__name__)
testsuite.init_test(testresult)
result = TestResultCollection([testresult], False)
if not testsuite.root_test_result:
testsuite.root_test_result = testresult
try:
testsuite.pre_test()
except:
Expand All @@ -345,7 +356,9 @@ def run(self, testsuite, testresult_factory):
else:
raise ValueError("Invalid exec mode: %s" % self._exec_mode)

testresult.begin_step("post_test")
if testsuite.root_test_result and testsuite.root_test_result != testresult:
testsuite.root_test_result.begin_step("【%s】 - post_test" % testsuite.__class__.__name__)
testresult.begin_step("【%s】 - post_test" % testsuite.__class__.__name__)
try:
testsuite.post_test()
except:
Expand Down Expand Up @@ -388,6 +401,7 @@ def __init__(self, testcases):
self.__testcases = testcases
self.__testresults = []
self.__current_stage = ""
self.__root_test_result = None

def __iter__(self):
for it in self.__testcases:
Expand Down Expand Up @@ -440,6 +454,14 @@ def current_stage(self):
def current_stage(self, value):
self.__current_stage = value

@property
def root_test_result(self):
return self.__root_test_result

@root_test_result.setter
def root_test_result(self, value):
self.__root_test_result = value

@classmethod
def filter(cls, testcase):
if not cls.testcase_filter:
Expand Down
Loading