Commit c788ceaf2310d421c68596ceafe3e3f0fc46f859
1 parent
80791d85
tests: Add another warnings test
Showing
1 changed file
with
18 additions
and
0 deletions
tests/common/log_helper/test_log_helper.py
| @@ -168,6 +168,24 @@ class TestLogHelper(unittest.TestCase): | @@ -168,6 +168,24 @@ class TestLogHelper(unittest.TestCase): | ||
| 168 | self.assertIn(log_helper_test_main.ACTUAL_WARNING, jout[-2]['msg']) | 168 | self.assertIn(log_helper_test_main.ACTUAL_WARNING, jout[-2]['msg']) |
| 169 | self.assertIn(log_helper_test_imported.ACTUAL_WARNING, jout[-1]['msg']) | 169 | self.assertIn(log_helper_test_imported.ACTUAL_WARNING, jout[-1]['msg']) |
| 170 | 170 | ||
| 171 | + def test_warnings(self): | ||
| 172 | + """Check that warnings are captured and printed correctly""" | ||
| 173 | + output = self._run_test(['enable', 'warn', 'warning']) | ||
| 174 | + | ||
| 175 | + expect = '\n'.join([ | ||
| 176 | + 'WARNING ' + log_helper_test_main.WARNING_MESSAGE, | ||
| 177 | + 'ERROR ' + log_helper_test_main.ERROR_MESSAGE, | ||
| 178 | + 'CRITICAL ' + log_helper_test_main.CRITICAL_MESSAGE, | ||
| 179 | + 'WARNING ' + log_helper_test_imported.WARNING_MESSAGE, | ||
| 180 | + 'ERROR ' + log_helper_test_imported.ERROR_MESSAGE, | ||
| 181 | + 'CRITICAL ' + log_helper_test_imported.CRITICAL_MESSAGE, | ||
| 182 | + 'WARNING ' + log_helper_test_main.ACTUAL_WARNING, | ||
| 183 | + ' warnings.warn(ACTUAL_WARNING)', # warnings include source line | ||
| 184 | + 'WARNING ' + log_helper_test_imported.ACTUAL_WARNING, | ||
| 185 | + ' warnings.warn(ACTUAL_WARNING)', # warnings include source line | ||
| 186 | + ]) | ||
| 187 | + self.assertEqual(output, expect) | ||
| 188 | + | ||
| 171 | def _assert_json_messages(self, output, messages): | 189 | def _assert_json_messages(self, output, messages): |
| 172 | try: | 190 | try: |
| 173 | json_data = json.loads(output) | 191 | json_data = json.loads(output) |