Skip to content

Commit ecac572

Browse files
authored
Remove PytestRemovedIn9Warning (#14299)
Per our deprecation policy. Fix #13893.
1 parent 6aafcdc commit ecac572

6 files changed

Lines changed: 27 additions & 15 deletions

File tree

doc/en/conf.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,24 @@ def setup(app: sphinx.application.Sphinx) -> None:
306306

307307
# legacypath.py monkey-patches pytest.Testdir in. Import the file so
308308
# that autodoc can discover references to it.
309+
# Workaround for Sphinx bug with Python 3.14:
310+
# inspect.getsource() returns '\n' instead of raising OSError for classes
311+
# whose __module__ doesn't match the file they're defined in, causing
312+
# get_type_comment() to crash with IndexError on empty ast.parse result.
313+
# See: https://github.com/sphinx-doc/sphinx/issues/14345
314+
import sys
315+
309316
import _pytest.legacypath # noqa: F401
317+
318+
if sys.version_info >= (3, 14):
319+
from sphinx.ext.autodoc._dynamic import _type_comments
320+
321+
_orig_get_type_comment = _type_comments.get_type_comment
322+
323+
def _get_type_comment_safe(obj: object, bound_method: bool = False) -> object:
324+
try:
325+
return _orig_get_type_comment(obj, bound_method)
326+
except IndexError:
327+
return None
328+
329+
_type_comments.get_type_comment = _get_type_comment_safe # type: ignore[assignment]

doc/en/reference/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ Custom warnings generated in some situations such as improper usage or deprecate
12911291
.. autoclass:: pytest.PytestReturnNotNoneWarning
12921292
:show-inheritance:
12931293

1294-
.. autoclass:: pytest.PytestRemovedIn9Warning
1294+
.. autoclass:: pytest.PytestRemovedIn10Warning
12951295
:show-inheritance:
12961296

12971297
.. autoclass:: pytest.PytestUnknownMarkWarning

src/_pytest/warning_types.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ class PytestDeprecationWarning(PytestWarning, DeprecationWarning):
5050
__module__ = "pytest"
5151

5252

53-
class PytestRemovedIn9Warning(PytestDeprecationWarning):
54-
"""Warning class for features that will be removed in pytest 9."""
55-
56-
__module__ = "pytest"
57-
58-
5953
class PytestRemovedIn10Warning(PytestDeprecationWarning):
6054
"""Warning class for features that will be removed in pytest 10."""
6155

src/_pytest/warnings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def catch_warnings_for_item(
4141
warnings.filterwarnings("always", category=DeprecationWarning)
4242
warnings.filterwarnings("always", category=PendingDeprecationWarning)
4343

44-
warnings.filterwarnings("error", category=pytest.PytestRemovedIn9Warning)
44+
# To be enabled in pytest 10.0.0.
45+
# warnings.filterwarnings("error", category=pytest.PytestRemovedIn10Warning)
4546

4647
apply_warning_filters(config_filters, cmdline_filters)
4748

src/pytest/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
from _pytest.warning_types import PytestDeprecationWarning
8484
from _pytest.warning_types import PytestExperimentalApiWarning
8585
from _pytest.warning_types import PytestFDWarning
86-
from _pytest.warning_types import PytestRemovedIn9Warning
8786
from _pytest.warning_types import PytestRemovedIn10Warning
8887
from _pytest.warning_types import PytestReturnNotNoneWarning
8988
from _pytest.warning_types import PytestUnhandledThreadExceptionWarning
@@ -135,7 +134,6 @@
135134
"PytestExperimentalApiWarning",
136135
"PytestFDWarning",
137136
"PytestPluginManager",
138-
"PytestRemovedIn9Warning",
139137
"PytestRemovedIn10Warning",
140138
"PytestReturnNotNoneWarning",
141139
"PytestUnhandledThreadExceptionWarning",

testing/test_warnings.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,7 @@ def test_invalid_regex_in_filterwarning(self, pytester: Pytester) -> None:
562562
)
563563

564564

565-
# In 9.1, uncomment below and change RemovedIn9 -> RemovedIn10.
566-
# @pytest.mark.skip("not relevant until pytest 10.0")
565+
@pytest.mark.skip("not relevant until pytest 10.0")
567566
@pytest.mark.parametrize("change_default", [None, "ini", "cmdline"])
568567
def test_removed_in_x_warning_as_error(pytester: Pytester, change_default) -> None:
569568
"""This ensures that PytestRemovedInXWarnings raised by pytest are turned into errors.
@@ -575,20 +574,20 @@ def test_removed_in_x_warning_as_error(pytester: Pytester, change_default) -> No
575574
"""
576575
import warnings, pytest
577576
def test():
578-
warnings.warn(pytest.PytestRemovedIn9Warning("some warning"))
577+
warnings.warn(pytest.PytestRemovedIn10Warning("some warning"))
579578
"""
580579
)
581580
if change_default == "ini":
582581
pytester.makeini(
583582
"""
584583
[pytest]
585584
filterwarnings =
586-
ignore::pytest.PytestRemovedIn9Warning
585+
ignore::pytest.PytestRemovedIn10Warning
587586
"""
588587
)
589588

590589
args = (
591-
("-Wignore::pytest.PytestRemovedIn9Warning",)
590+
("-Wignore::pytest.PytestRemovedIn10Warning",)
592591
if change_default == "cmdline"
593592
else ()
594593
)

0 commit comments

Comments
 (0)