okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
f6dbf0b
main
1"""Load unittest files without letting an empty selection report success.""" 2 3import importlib .util 4from pathlib import Path 5import sys 6import unittest 7 8 9def suite_for (path ,test_name = None ): 10path = Path (path ).resolve () 11sys .path .insert (0 ,str (path .parent )) 12spec = importlib .util .spec_from_file_location (path .stem ,path ) 13assert spec is not None and spec .loader is not None 14module = importlib .util .module_from_spec (spec ) 15sys .modules [path .stem ]= module 16spec .loader .exec_module (module ) 17loader = unittest .TestLoader () 18suite = ( 19loader .loadTestsFromName (test_name ,module ) 20if test_name 21else loader .loadTestsFromModule (module ) 22 ) 23if suite .countTestCases ()== 0 : 24raise ValueError (f"no tests collected from { path } " ) 25return suite 26 27 28def main (): 29try : 30suite = suite_for (sys .argv [1 ]) 31except ValueError as error : 32error ,file = sys .stderr ) 33return 1 34return 0 if unittest .TextTestRunner (verbosity = 2 ).run (suite ).wasSuccessful ()else 1 35 36 37if __name__ == "__main__" : 38sys .exit (main ())