(self)
| 2474 | record=True) |
| 2475 | |
| 2476 | def __enter__(self): |
| 2477 | if self._entered: |
| 2478 | raise RuntimeError("cannot enter suppress_warnings twice.") |
| 2479 | |
| 2480 | self._orig_show = warnings.showwarning |
| 2481 | self._catch_warnings = warnings.catch_warnings() |
| 2482 | self._catch_warnings.__enter__() |
| 2483 | |
| 2484 | self._entered = True |
| 2485 | self._tmp_suppressions = [] |
| 2486 | self._tmp_modules = set() |
| 2487 | self._forwarded = set() |
| 2488 | |
| 2489 | self.log = [] # reset global log (no need to keep same list) |
| 2490 | |
| 2491 | for cat, mess, _, mod, log in self._suppressions: |
| 2492 | if log is not None: |
| 2493 | del log[:] # clear the log |
| 2494 | if mod is None: |
| 2495 | warnings.filterwarnings( |
| 2496 | "always", category=cat, message=mess) |
| 2497 | else: |
| 2498 | module_regex = mod.__name__.replace('.', r'\.') + '$' |
| 2499 | warnings.filterwarnings( |
| 2500 | "always", category=cat, message=mess, |
| 2501 | module=module_regex) |
| 2502 | self._tmp_modules.add(mod) |
| 2503 | warnings.showwarning = self._showwarning |
| 2504 | self._clear_registries() |
| 2505 | |
| 2506 | return self |
| 2507 | |
| 2508 | def __exit__(self, *exc_info): |
| 2509 | warnings.showwarning = self._orig_show |
no test coverage detected