Skip to content

Commit

Permalink
test: try to silence a new warning
Browse files Browse the repository at this point in the history
For example:
```
.tox/anypy/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:1004: 50 warnings
  /Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:1004: DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
    expl_format = self.pop_format_context(ast.Str(expl))
```
  • Loading branch information
nedbat committed May 11, 2023
1 parent f2a9648 commit ee17e7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ filterwarnings = [
"ignore:the imp module is deprecated in favour of importlib:DeprecationWarning",
"ignore:distutils Version classes are deprecated:DeprecationWarning",
"ignore:The distutils package is deprecated and slated for removal in Python 3.12:DeprecationWarning",
"ignore:is deprecated and will be removed in Python 3.14; use ast.Constant instead:DeprecationWarning",
]

# xfail tests that pass should fail the test suite
Expand Down
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def set_warnings() -> None:
warnings.simplefilter("once", DeprecationWarning)

# Warnings to suppress:
# How come these warnings are successfully suppressed here, but not in setup.cfg??

This comment has been minimized.

Copy link
@webknjaz

webknjaz Jun 16, 2023

Contributor

@nedbat
A wild guess: these are suppressed per-test, so they likely don't suppress warnings coming from pytest's own internal machinery… Plus, having them in Python lets one do conditionals like the one with PyPy below. I've actually been considering writing a plugin for such cases because at some point I was adding certain deprecation suppressions only under certain pytest or Python versions. Also, it's sometimes harder to reason about how those regexes are escaped by a parser in an ini-file which setup.cfg essentially is. It might be better with pyproject.toml.

# How come these warnings are successfully suppressed here, but not in pyproject.toml??

warnings.filterwarnings(
"ignore",
Expand All @@ -54,6 +54,13 @@ def set_warnings() -> None:
message=r"module 'sre_constants' is deprecated",
)

# From _pytest/assertion/rewrite.py
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message=r"is deprecated and will be removed in Python 3.14; use ast.Constant instead",
)

warnings.filterwarnings(
"ignore",
category=pytest.PytestRemovedIn8Warning,
Expand Down

0 comments on commit ee17e7c

Please sign in to comment.