Skip to content

Commit

Permalink
better handle errors raised while applying filterwarnings (pytest-dev…
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesaracil-ulti committed Oct 9, 2020
1 parent dbd082a commit 79abdcb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/7864.improvement.rst
@@ -0,0 +1 @@
better handle errors raised while applying filterwarnings
9 changes: 8 additions & 1 deletion src/_pytest/config/__init__.py
Expand Up @@ -1569,7 +1569,14 @@ def parse_warning_filter(
parts.append("")
action_, message, category_, module, lineno_ = [s.strip() for s in parts]
action: str = warnings._getaction(action_) # type: ignore[attr-defined]
category: Type[Warning] = warnings._getcategory(category_) # type: ignore[attr-defined]
try:
category: Type[Warning] = warnings._getcategory(category_) # type: ignore[attr-defined] # noqa: E501
except Exception as e:
raise Exception(
"Error while processing warning rules. Please make sure importing "
"the warning classes defined in filterwarning doesn't trigger an "
"exception."
) from e
if message and escape:
message = re.escape(message)
if module and escape:
Expand Down

0 comments on commit 79abdcb

Please sign in to comment.