-
- Notifications
You must be signed in to change notification settings - Fork 3k
Description
Moved from #2445 (comment):
The warnings plugin does not handle the case where the logging module's captureWarnings mechanism is used to route warnings through the logging module, and therefore allows to filter them:
logging.captureWarnings(True) logging.getLogger('py.warnings').addFilter(filter_deprecation_warnings)logging.captureWarnings monkeypatches warnings.showwarning (in Python 3.6) to log them instead (as a warning).
pytest could maybe check if logging._warnings_showwarning is not None to detect if warnings are supposed to go through logging.
With or without this in setup.cfg:
[tool:pytest] filterwarnings = once::DeprecationWarning once::PendingDeprecationWarningThis mechanism is useful if you want to have fine-grained support on filtering, e.g. based on some (dynamic) path in the warning message.
I am not sure if it is worth the effort to do something in this regard, and if so what the best option would be: maybe transferring it into a log record and see if the py.warnings handlers would filter them?