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