Skip to content

Commit 883121b

Browse files
committed
Show skipped tests at end of CI run with reason.
On CI we don't want the full output of --verbose but fail when tests are skipped. This is only indicated by a "s" inbetween many dots. So show a list of skipped tests and their reason at the end. This also allows easy filtering.
1 parent ba1caf1 commit 883121b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test/framework/suite.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,30 @@ def run(self, *args, **kwargs):
137137
return res
138138

139139

140-
def load_tests(loader, tests, pattern):
140+
class SkipSummaryResult(unittest.TextTestResult):
141+
"""Decorator that prints skipped tests at the end of the run if in CI environment."""
142+
def __init__(self, stream, descriptions, verbosity, *args, **kwargs):
143+
super().__init__(stream, descriptions, verbosity, *args, **kwargs)
144+
self._verbosity = verbosity
145+
146+
def stopTestRun(self):
147+
super().stopTestRun()
148+
if 'CI' in os.environ and self.skipped:
149+
print("\n=== Skipped tests ===")
150+
for test, reason in self.skipped:
151+
print(f"{self.getDescription(test)}: {reason}")
152+
153+
154+
class SkipSummaryRunner(unittest.TextTestRunner):
155+
resultclass = SkipSummaryResult
156+
157+
158+
def load_tests(loader, _tests, _pattern):
141159
return EasyBuildFrameworkTestSuite(loader)
142160

143161

144162
if __name__ == '__main__':
145163
if len(sys.argv) > 1 and sys.argv[1].startswith('-'):
146-
unittest.main()
164+
unittest.main(testRunner=SkipSummaryRunner())
147165
else:
148-
unittest.TextTestRunner().run(EasyBuildFrameworkTestSuite(None))
166+
SkipSummaryRunner().run(EasyBuildFrameworkTestSuite(None))

0 commit comments

Comments
 (0)