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