tests/mixins.py
raw| 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | from __future__ import absolute_import, unicode_literals |
| 4 | |
| 5 | import warnings |
| 6 | |
| 7 | |
| 8 | class WarningTestCaseMixin(object): |
| 9 | """ |
| 10 | TestCase mixin to catch warnings |
| 11 | """ |
| 12 | |
| 13 | def assertWarning(self, warning, callable, *args, **kwargs): |
| 14 | with warnings.catch_warnings(record=True) as warning_list: |
| 15 | warnings.simplefilter(action="always") |
| 16 | callable(*args, **kwargs) |
| 17 | self.assertTrue(any(item.category == warning for item in warning_list)) |