diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2018-11-13 18:51:55 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2018-11-13 18:51:55 +0300 |
commit | 4d7f708b258e9fb4280883b4f64700367dcbb40d (patch) | |
tree | e4dee9750e929c8fb7f60509f765fc9e69a1ef8c /test/unit.py | |
parent | ff9bed64da495b6c234bcfa4dcf18932730e58e7 (diff) | |
download | unit-4d7f708b258e9fb4280883b4f64700367dcbb40d.tar.gz unit-4d7f708b258e9fb4280883b4f64700367dcbb40d.tar.bz2 |
Tests: leave unit.log in case of error or failure.
Diffstat (limited to '')
-rw-r--r-- | test/unit.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/test/unit.py b/test/unit.py index 98a0a4db..edfa39a0 100644 --- a/test/unit.py +++ b/test/unit.py @@ -25,11 +25,31 @@ class TestUnit(unittest.TestCase): def tearDown(self): self.stop() + # detect errors and failures for current test + + def list2reason(exc_list): + if exc_list and exc_list[-1][0] is self: + return exc_list[-1][1] + + if hasattr(self, '_outcome'): + result = self.defaultTestResult() + self._feedErrorsToResult(result, self._outcome.errors) + else: + result = getattr(self, '_outcomeForDoCleanups', + self._resultForDoCleanups) + + success = not list2reason(result.errors) \ + and not list2reason(result.failures) + + # check unit.log for alerts + with open(self.testdir + '/unit.log', 'r', encoding='utf-8', errors='ignore') as f: self._check_alerts(f.read()) - if '--leave' not in sys.argv: + # remove unit.log + + if '--leave' not in sys.argv and success: shutil.rmtree(self.testdir) def check_modules(self, *modules): |