blob: 3da567f8b5b20662c03a86a9bba14ef75a35ca1e [file] [log] [blame]
Alex3bc95f62020-03-05 17:00:04 -06001import os
2import shutil
3import unittest
4
5from unittest import TextTestResult, TextTestRunner
6from tests.test_base import tests_dir
7from tests.test_packages import _res_dir
8
9
10class MyTestResult(TextTestResult):
11 def getDescription(self, test):
12 # return super().getDescription(test)
13 doc_first_line = test.shortDescription()
14 if self.descriptions and doc_first_line:
15 return '\n'.join((str(test), doc_first_line))
16 else:
17 # return str(test)
18 return "{}.{}.{}".format(
19 test.__class__.__module__,
20 test.__class__.__name__,
21 test._testMethodName
22 )
23
24
25class MyTestRunner(TextTestRunner):
26 resultclass = MyTestResult
27
28
29def _cleanup():
30 _fpath = [
31 "repo.info.tgz",
32 "repo.versions.tgz",
33 "pkg.descriptions.tgz"
34 ]
35 for _p in _fpath:
36 _fp = os.path.join(_res_dir, _p)
37 if os.path.exists(_fp):
38 os.remove(_fp)
39
40 _ferr = os.path.join(_res_dir, "fakeerrors")
41 if os.path.exists(_ferr):
42 shutil.rmtree(_ferr)
43
44
45if __name__ == '__main__':
46 # remove old files if exists
47 _cleanup()
48
49 # start tests
50 suite = unittest.TestLoader().discover(tests_dir, "test_*", tests_dir)
51 runner = MyTestRunner(verbosity=3)
52 runner.run(suite)
53
54 # cleanup after testrun
55 _cleanup()