File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4848 # PowerShell, so the Windows job failed on the shell rather than on a
4949 # test. Runners print full output on failure, so no log scraping is
5050 # needed here.
51- run : python -m unittest test .py test_poc_vulnerability.py -v
51+ run : python run_ci_tests .py
Original file line number Diff line number Diff line change 1+ """Run the unit tests and surface failures as GitHub annotations.
2+
3+ Windows runners execute ``run:`` steps with PowerShell, so shell tricks for
4+ piping or scraping output are not portable. Doing it in Python keeps the
5+ workflow identical on every runner, and the ``::error`` lines land in the
6+ check-run annotations even when the raw job log cannot be retrieved.
7+ """
8+ import io
9+ import sys
10+ import unittest
11+
12+ RESULT_FILE = "suite-output.txt"
13+
14+
15+ def main ():
16+ sys .path .insert (0 , "." )
17+ loader = unittest .TestLoader ()
18+ suite = unittest .TestSuite ([
19+ loader .loadTestsFromName ("test" ),
20+ loader .loadTestsFromName ("test_poc_vulnerability" ),
21+ ])
22+ buffer = io .StringIO ()
23+ runner = unittest .TextTestRunner (stream = buffer , verbosity = 2 )
24+ result = runner .run (suite )
25+ output = buffer .getvalue ()
26+ print (output )
27+
28+ problems = [(str (test ), traceback ) for test , traceback in
29+ result .errors + result .failures ]
30+ for name , traceback in problems :
31+ print (f"::error title={ name } ::{ traceback .strip ().splitlines ()[- 1 ][:200 ]} " )
32+
33+ if problems :
34+ with open (RESULT_FILE , "w" , encoding = "utf-8" ) as handle :
35+ handle .write (output )
36+ return 1
37+ return 0
38+
39+
40+ if __name__ == "__main__" :
41+ sys .exit (main ())
You can’t perform that action at this time.
0 commit comments