Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit 03d0cfa

Browse files
committed
return simplified results array
1 parent f1ffd38 commit 03d0cfa

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

packages/unittest_runner/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "unittest_runner"
7-
version = "0.0.1"
7+
version = "0.1.0"
88
dependencies = ["unittest"]

packages/unittest_runner/unittest_runner/run_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
# Run the tests in the given file pattern and display the results to the user.
55
# Validation tests use the ValidationTestResult class to display only the short description of the test.
66
def run_validation_tests(file_pattern):
7-
run_tests(file_pattern, ValidationTestResult)
7+
result = run_tests(file_pattern, ValidationTestResult)
8+
return result.simplified_results
89

910
# Run the tests in the given file pattern and display the results to the user.
1011
# Student tests use the standard TextTestResult class to display the test name and short description.
1112
def run_student_tests(file_pattern):
12-
run_tests(file_pattern, unittest.TextTestResult)
13+
return run_tests(file_pattern, unittest.TextTestResult)
1314

1415
def run_tests(file_pattern, resultclass):
1516
loader = unittest.TestLoader()
1617
test_suite = loader.discover('.', file_pattern)
1718
runner = unittest.TextTestRunner(verbosity=2, resultclass=resultclass)
1819
result = runner.run(test_suite)
20+
return result

packages/unittest_runner/unittest_runner/validation_runner.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from unittest import TextTestResult
33

44
class ValidationTestResult(TextTestResult):
5+
simplified_results = []
6+
7+
58
# The default behavior is to display the test name and short description.
69
# We want to display only the short description if it exists, otherwise just the test name.
710
# Students don't see the tests, so we don't need to display the test name.
@@ -12,3 +15,27 @@ def getDescription(self, test):
1215
return doc_first_line
1316
else:
1417
return str(test)
18+
19+
def addSuccess(self, test):
20+
super(ValidationTestResult, self).addSuccess(test)
21+
self.simplified_results.append({'name': self.getDescription(test), 'result': "PASS"})
22+
23+
def addError(self, test, err):
24+
super(ValidationTestResult, self).addError(test, err)
25+
self.simplified_results.append({'name': self.getDescription(test), 'result': "ERROR"})
26+
27+
def addFailure(self, test, err):
28+
super(ValidationTestResult, self).addFailure(test, err)
29+
self.simplified_results.append({'name': self.getDescription(test), 'result': "FAIL"})
30+
31+
def addSkip(self, test, reason):
32+
super(ValidationTestResult, self).addSkip(test, reason)
33+
self.simplified_results.append({'name': self.getDescription(test), 'result': "SKIP"})
34+
35+
def addExpectedFailure(self, test, err):
36+
super(ValidationTestResult, self).addExpectedFailure(test, err)
37+
self.simplified_results.append({'name': self.getDescription(test), 'result': "EXPECTED_FAILURE"})
38+
39+
def addUnexpectedSuccess(self, test):
40+
super(ValidationTestResult, self).addUnexpectedSuccess(test)
41+
self.simplified_results.append({'name': self.getDescription(test), 'result': "UNEXPECTED_SUCCESS"})

0 commit comments

Comments
 (0)