Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 1 | import os |
| 2 | import shutil |
| 3 | import unittest |
| 4 | |
| 5 | from unittest import TextTestResult, TextTestRunner |
| 6 | from tests.test_base import tests_dir |
| 7 | from tests.test_packages import _res_dir |
| 8 | |
| 9 | |
| 10 | class 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 | |
| 25 | class MyTestRunner(TextTestRunner): |
| 26 | resultclass = MyTestResult |
| 27 | |
| 28 | |
| 29 | def _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 | |
| 45 | if __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() |