| 1 |
from unittest import TestCase |
| 2 |
|
| 3 |
|
| 4 |
class BaseTestCase(TestCase): |
| 5 |
def setUp(self): |
| 6 |
super().setUp() |
| 7 |
self.__patches = [] |
| 8 |
|
| 9 |
self.error = NotImplemented |
| 10 |
|
| 11 |
def add_patch(self, patch): |
| 12 |
patch.start() |
| 13 |
self.__patches.append(patch) |
| 14 |
|
| 15 |
def tearDown(self): |
| 16 |
super().tearDown() |
| 17 |
for patch in reversed(self.__patches): |
| 18 |
patch.stop() |
| 19 |
|
| 20 |
def then_error_was_raised(self, error_cls, allowed_substrings=()): |
| 21 |
self.assertIsInstance(self.error, error_cls) |
| 22 |
self.assertTrue( |
| 23 |
any(mesg in str(self.error) for mesg in allowed_substrings), |
| 24 |
"Didn't found any of the expected messages (%r) -- message was: %r" |
| 25 |
% (allowed_substrings, self.error), |
| 26 |
) |