(self, exc_type, exc_value, tb)
| 305 | return self |
| 306 | |
| 307 | def __exit__(self, exc_type, exc_value, tb): |
| 308 | self.warnings_manager.__exit__(exc_type, exc_value, tb) |
| 309 | if exc_type is not None: |
| 310 | # let unexpected exceptions pass through |
| 311 | return |
| 312 | try: |
| 313 | exc_name = self.expected.__name__ |
| 314 | except AttributeError: |
| 315 | exc_name = str(self.expected) |
| 316 | first_matching = None |
| 317 | for m in self.warnings: |
| 318 | w = m.message |
| 319 | if not isinstance(w, self.expected): |
| 320 | continue |
| 321 | if first_matching is None: |
| 322 | first_matching = w |
| 323 | if (self.expected_regex is not None and |
| 324 | not self.expected_regex.search(str(w))): |
| 325 | continue |
| 326 | # store warning for later retrieval |
| 327 | self.warning = w |
| 328 | self.filename = m.filename |
| 329 | self.lineno = m.lineno |
| 330 | return |
| 331 | # Now we simply try to choose a helpful failure message |
| 332 | if first_matching is not None: |
| 333 | self._raiseFailure('"{}" does not match "{}"'.format( |
| 334 | self.expected_regex.pattern, str(first_matching))) |
| 335 | if self.obj_name: |
| 336 | self._raiseFailure("{} not triggered by {}".format(exc_name, |
| 337 | self.obj_name)) |
| 338 | else: |
| 339 | self._raiseFailure("{} not triggered".format(exc_name)) |
| 340 | |
| 341 | |
| 342 | class _AssertNotWarnsContext(_AssertWarnsContext): |
no test coverage detected