From 93c8822f26c90e3b440021b26da62e6aa6d49158 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 13 Sep 2019 22:45:45 +0300 Subject: [PATCH] Fix check_untyped_defs errors in warnings --- src/_pytest/warnings.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/_pytest/warnings.py b/src/_pytest/warnings.py index d817a5cfa..8fdb61c2b 100644 --- a/src/_pytest/warnings.py +++ b/src/_pytest/warnings.py @@ -66,6 +66,8 @@ def catch_warnings_for_item(config, ihook, when, item): cmdline_filters = config.getoption("pythonwarnings") or [] inifilters = config.getini("filterwarnings") with warnings.catch_warnings(record=True) as log: + # mypy can't infer that record=True means log is not None; help it. + assert log is not None if not sys.warnoptions: # if user is not explicitly configuring warning filters, show deprecation warnings by default (#2908) @@ -145,6 +147,8 @@ def _issue_warning_captured(warning, hook, stacklevel): with warnings.catch_warnings(record=True) as records: warnings.simplefilter("always", type(warning)) warnings.warn(warning, stacklevel=stacklevel) + # Mypy can't infer that record=True means records is not None; help it. + assert records is not None hook.pytest_warning_captured.call_historic( kwargs=dict(warning_message=records[0], when="config", item=None) )