Skip to content

Commit c7be96d

Browse files
authored
Merge pull request #9392 from bluetech/rm-7-deprecated
Remove deprecations scheduled for removal in pytest 7.1
2 parents 7ae23ff + ee93557 commit c7be96d

19 files changed

+45
-366
lines changed

changelog/8838.breaking.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
As per our policy, the following features have been deprecated in the 6.X series and are now
2+
removed:
3+
4+
* ``pytest._fillfuncargs`` function.
5+
6+
* ``pytest_warning_captured`` hook - use ``pytest_warning_recorded`` instead.
7+
8+
* ``-k -foobar`` syntax - use ``-k 'not foobar'`` instead.
9+
10+
* ``-k foobar:`` syntax.
11+
12+
* ``pytest.collect`` module - import from ``pytest`` directly.
13+
14+
For more information consult
15+
`Deprecations and Removals <https://docs.pytest.org/en/latest/deprecations.html>`__ in the docs.

doc/en/deprecations.rst

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,29 +250,42 @@ The ``yield_fixture`` function/decorator
250250
It has been so for a very long time, so can be search/replaced safely.
251251

252252

253-
The ``pytest_warning_captured`` hook
254-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
253+
Removed Features
254+
----------------
255255

256-
.. deprecated:: 6.0
256+
As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after
257+
an appropriate period of deprecation has passed.
257258

258-
This hook has an `item` parameter which cannot be serialized by ``pytest-xdist``.
259-
260-
Use the ``pytest_warning_recored`` hook instead, which replaces the ``item`` parameter
261-
by a ``nodeid`` parameter.
262259

263260
The ``pytest.collect`` module
264261
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265262

266263
.. deprecated:: 6.0
264+
.. versionremoved:: 7.0
267265

268266
The ``pytest.collect`` module is no longer part of the public API, all its names
269267
should now be imported from ``pytest`` directly instead.
270268

271269

270+
271+
The ``pytest_warning_captured`` hook
272+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273+
274+
.. deprecated:: 6.0
275+
.. versionremoved:: 7.0
276+
277+
This hook has an `item` parameter which cannot be serialized by ``pytest-xdist``.
278+
279+
Use the ``pytest_warning_recored`` hook instead, which replaces the ``item`` parameter
280+
by a ``nodeid`` parameter.
281+
282+
283+
272284
The ``pytest._fillfuncargs`` function
273285
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
274286

275287
.. deprecated:: 6.0
288+
.. versionremoved:: 7.0
276289

277290
This function was kept for backward compatibility with an older plugin.
278291

@@ -281,12 +294,6 @@ it, use `function._request._fillfixtures()` instead, though note this is not
281294
a public API and may break in the future.
282295

283296

284-
Removed Features
285-
----------------
286-
287-
As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after
288-
an appropriate period of deprecation has passed.
289-
290297
``--no-print-logs`` command-line option
291298
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
292299

doc/en/how-to/plugins.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ Here is a little annotated list for some popular plugins:
5151
* :pypi:`pytest-flakes`:
5252
check source code with pyflakes.
5353

54-
* :pypi:`oejskit`:
55-
a plugin to run javascript unittests in live browsers.
56-
5754
To see a complete list of all plugins with their latest testing
5855
status against different pytest and Python versions, please visit
5956
:ref:`plugin-list`.

doc/en/reference/reference.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,6 @@ Session related reporting hooks:
758758
.. autofunction:: pytest_terminal_summary
759759
.. autofunction:: pytest_fixture_setup
760760
.. autofunction:: pytest_fixture_post_finalizer
761-
.. autofunction:: pytest_warning_captured
762761
.. autofunction:: pytest_warning_recorded
763762

764763
Central hook for reporting about test execution:

src/_pytest/config/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,14 +1330,6 @@ def issue_config_time_warning(self, warning: Warning, stacklevel: int) -> None:
13301330
if records:
13311331
frame = sys._getframe(stacklevel - 1)
13321332
location = frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name
1333-
self.hook.pytest_warning_captured.call_historic(
1334-
kwargs=dict(
1335-
warning_message=records[0],
1336-
when="config",
1337-
item=None,
1338-
location=location,
1339-
)
1340-
)
13411333
self.hook.pytest_warning_recorded.call_historic(
13421334
kwargs=dict(
13431335
warning_message=records[0],

src/_pytest/deprecated.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from warnings import warn
1212

1313
from _pytest.warning_types import PytestDeprecationWarning
14-
from _pytest.warning_types import PytestRemovedIn7Warning
1514
from _pytest.warning_types import PytestRemovedIn8Warning
1615
from _pytest.warning_types import UnformattedWarning
1716

@@ -24,39 +23,13 @@
2423
}
2524

2625

27-
FILLFUNCARGS = UnformattedWarning(
28-
PytestRemovedIn7Warning,
29-
"{name} is deprecated, use "
30-
"function._request._fillfixtures() instead if you cannot avoid reaching into internals.",
31-
)
32-
33-
PYTEST_COLLECT_MODULE = UnformattedWarning(
34-
PytestRemovedIn7Warning,
35-
"pytest.collect.{name} was moved to pytest.{name}\n"
36-
"Please update to the new name.",
37-
)
38-
3926
# This can be* removed pytest 8, but it's harmless and common, so no rush to remove.
4027
# * If you're in the future: "could have been".
4128
YIELD_FIXTURE = PytestDeprecationWarning(
4229
"@pytest.yield_fixture is deprecated.\n"
4330
"Use @pytest.fixture instead; they are the same."
4431
)
4532

46-
MINUS_K_DASH = PytestRemovedIn7Warning(
47-
"The `-k '-expr'` syntax to -k is deprecated.\nUse `-k 'not expr'` instead."
48-
)
49-
50-
MINUS_K_COLON = PytestRemovedIn7Warning(
51-
"The `-k 'expr:'` syntax to -k is deprecated.\n"
52-
"Please open an issue if you use this and want a replacement."
53-
)
54-
55-
WARNING_CAPTURED_HOOK = PytestRemovedIn7Warning(
56-
"The pytest_warning_captured is deprecated and will be removed in a future release.\n"
57-
"Please use pytest_warning_recorded instead."
58-
)
59-
6033
WARNING_CMDLINE_PREPARSE_HOOK = PytestRemovedIn8Warning(
6134
"The pytest_cmdline_preparse hook is deprecated and will be removed in a future release. \n"
6235
"Please use pytest_load_initial_conftests hook instead."

src/_pytest/fixtures.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
from _pytest.config import Config
5353
from _pytest.config.argparsing import Parser
5454
from _pytest.deprecated import check_ispytest
55-
from _pytest.deprecated import FILLFUNCARGS
5655
from _pytest.deprecated import YIELD_FIXTURE
5756
from _pytest.mark import Mark
5857
from _pytest.mark import ParameterSet
@@ -73,7 +72,6 @@
7372
from _pytest.scope import _ScopeName
7473
from _pytest.main import Session
7574
from _pytest.python import CallSpec2
76-
from _pytest.python import Function
7775
from _pytest.python import Metafunc
7876

7977

@@ -352,41 +350,6 @@ def reorder_items_atscope(
352350
return items_done
353351

354352

355-
def _fillfuncargs(function: "Function") -> None:
356-
"""Fill missing fixtures for a test function, old public API (deprecated)."""
357-
warnings.warn(FILLFUNCARGS.format(name="pytest._fillfuncargs()"), stacklevel=2)
358-
_fill_fixtures_impl(function)
359-
360-
361-
def fillfixtures(function: "Function") -> None:
362-
"""Fill missing fixtures for a test function (deprecated)."""
363-
warnings.warn(
364-
FILLFUNCARGS.format(name="_pytest.fixtures.fillfixtures()"), stacklevel=2
365-
)
366-
_fill_fixtures_impl(function)
367-
368-
369-
def _fill_fixtures_impl(function: "Function") -> None:
370-
"""Internal implementation to fill fixtures on the given function object."""
371-
try:
372-
request = function._request
373-
except AttributeError:
374-
# XXX this special code path is only expected to execute
375-
# with the oejskit plugin. It uses classes with funcargs
376-
# and we thus have to work a bit to allow this.
377-
fm = function.session._fixturemanager
378-
assert function.parent is not None
379-
fi = fm.getfixtureinfo(function.parent, function.obj, None)
380-
function._fixtureinfo = fi
381-
request = function._request = FixtureRequest(function, _ispytest=True)
382-
fm.session._setupstate.setup(function)
383-
request._fillfixtures()
384-
# Prune out funcargs for jstests.
385-
function.funcargs = {name: function.funcargs[name] for name in fi.argnames}
386-
else:
387-
request._fillfixtures()
388-
389-
390353
def get_direct_param_fixture_func(request):
391354
return request.param
392355

src/_pytest/hookspec.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
from pluggy import HookspecMarker
1515

16-
from _pytest.deprecated import WARNING_CAPTURED_HOOK
1716
from _pytest.deprecated import WARNING_CMDLINE_PREPARSE_HOOK
1817

1918
if TYPE_CHECKING:
@@ -777,41 +776,6 @@ def pytest_terminal_summary(
777776
"""
778777

779778

780-
@hookspec(historic=True, warn_on_impl=WARNING_CAPTURED_HOOK)
781-
def pytest_warning_captured(
782-
warning_message: "warnings.WarningMessage",
783-
when: "Literal['config', 'collect', 'runtest']",
784-
item: Optional["Item"],
785-
location: Optional[Tuple[str, int, str]],
786-
) -> None:
787-
"""(**Deprecated**) Process a warning captured by the internal pytest warnings plugin.
788-
789-
.. deprecated:: 6.0
790-
791-
This hook is considered deprecated and will be removed in a future pytest version.
792-
Use :func:`pytest_warning_recorded` instead.
793-
794-
:param warnings.WarningMessage warning_message:
795-
The captured warning. This is the same object produced by :py:func:`warnings.catch_warnings`, and contains
796-
the same attributes as the parameters of :py:func:`warnings.showwarning`.
797-
798-
:param str when:
799-
Indicates when the warning was captured. Possible values:
800-
801-
* ``"config"``: during pytest configuration/initialization stage.
802-
* ``"collect"``: during test collection.
803-
* ``"runtest"``: during test execution.
804-
805-
:param pytest.Item|None item:
806-
The item being executed if ``when`` is ``"runtest"``, otherwise ``None``.
807-
808-
:param tuple location:
809-
When available, holds information about the execution context of the captured
810-
warning (filename, linenumber, function). ``function`` evaluates to <module>
811-
when the execution context is at the module level.
812-
"""
813-
814-
815779
@hookspec(historic=True)
816780
def pytest_warning_recorded(
817781
warning_message: "warnings.WarningMessage",

src/_pytest/mark/__init__.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Generic mechanism for marking and selecting python functions."""
2-
import warnings
32
from typing import AbstractSet
43
from typing import Collection
54
from typing import List
@@ -23,8 +22,6 @@
2322
from _pytest.config import hookimpl
2423
from _pytest.config import UsageError
2524
from _pytest.config.argparsing import Parser
26-
from _pytest.deprecated import MINUS_K_COLON
27-
from _pytest.deprecated import MINUS_K_DASH
2825
from _pytest.stash import StashKey
2926

3027
if TYPE_CHECKING:
@@ -189,27 +186,14 @@ def deselect_by_keyword(items: "List[Item]", config: Config) -> None:
189186
if not keywordexpr:
190187
return
191188

192-
if keywordexpr.startswith("-"):
193-
# To be removed in pytest 8.0.0.
194-
warnings.warn(MINUS_K_DASH, stacklevel=2)
195-
keywordexpr = "not " + keywordexpr[1:]
196-
selectuntil = False
197-
if keywordexpr[-1:] == ":":
198-
# To be removed in pytest 8.0.0.
199-
warnings.warn(MINUS_K_COLON, stacklevel=2)
200-
selectuntil = True
201-
keywordexpr = keywordexpr[:-1]
202-
203189
expr = _parse_expression(keywordexpr, "Wrong expression passed to '-k'")
204190

205191
remaining = []
206192
deselected = []
207193
for colitem in items:
208-
if keywordexpr and not expr.evaluate(KeywordMatcher.from_item(colitem)):
194+
if not expr.evaluate(KeywordMatcher.from_item(colitem)):
209195
deselected.append(colitem)
210196
else:
211-
if selectuntil:
212-
keywordexpr = None
213197
remaining.append(colitem)
214198

215199
if deselected:

src/_pytest/warning_types.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ class PytestDeprecationWarning(PytestWarning, DeprecationWarning):
4848
__module__ = "pytest"
4949

5050

51-
@final
52-
class PytestRemovedIn7Warning(PytestDeprecationWarning):
53-
"""Warning class for features that will be removed in pytest 7."""
54-
55-
__module__ = "pytest"
56-
57-
5851
@final
5952
class PytestRemovedIn8Warning(PytestDeprecationWarning):
6053
"""Warning class for features that will be removed in pytest 8."""

0 commit comments

Comments
 (0)