From 75af2bfa06436752165df884d4666402529b1d6a Mon Sep 17 00:00:00 2001 From: Maximilian Cosmo Sitter <48606431+mcsitter@users.noreply.github.com> Date: Sat, 22 Aug 2020 16:17:50 +0200 Subject: [PATCH] Reintroduce warnings postponed in 6.0 (#7637) --- changelog/6981.deprecation.rst | 1 + changelog/7097.deprecation.rst | 6 ++++++ changelog/7210.deprecation.rst | 5 +++++ changelog/7255.deprecation.rst | 1 + src/_pytest/fixtures.py | 5 +++-- src/_pytest/hookspec.py | 5 ++--- src/_pytest/mark/__init__.py | 9 +++++---- src/pytest/collect.py | 6 +++--- testing/deprecated_test.py | 4 ---- 9 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 changelog/6981.deprecation.rst create mode 100644 changelog/7097.deprecation.rst create mode 100644 changelog/7210.deprecation.rst create mode 100644 changelog/7255.deprecation.rst diff --git a/changelog/6981.deprecation.rst b/changelog/6981.deprecation.rst new file mode 100644 index 00000000000..622dd9500ae --- /dev/null +++ b/changelog/6981.deprecation.rst @@ -0,0 +1 @@ +Deprecate the ``pytest.collect`` module: all its names can be imported from ``pytest`` directly. diff --git a/changelog/7097.deprecation.rst b/changelog/7097.deprecation.rst new file mode 100644 index 00000000000..b2aba597b61 --- /dev/null +++ b/changelog/7097.deprecation.rst @@ -0,0 +1,6 @@ +The ``pytest._fillfuncargs`` function is now deprecated. This function was kept +for backward compatibility with an older plugin. + +It's functionality is not meant to be used directly, but if you must replace +it, use `function._request._fillfixtures()` instead, though note this is not +a public API and may break in the future. diff --git a/changelog/7210.deprecation.rst b/changelog/7210.deprecation.rst new file mode 100644 index 00000000000..be0ead2214e --- /dev/null +++ b/changelog/7210.deprecation.rst @@ -0,0 +1,5 @@ +The special ``-k '-expr'`` syntax to ``-k`` is deprecated. Use ``-k 'not expr'`` +instead. + +The special ``-k 'expr:'`` syntax to ``-k`` is deprecated. Please open an issue +if you use this and want a replacement. diff --git a/changelog/7255.deprecation.rst b/changelog/7255.deprecation.rst new file mode 100644 index 00000000000..c6d56ab5a07 --- /dev/null +++ b/changelog/7255.deprecation.rst @@ -0,0 +1 @@ +The :func:`pytest_warning_captured` hook has been deprecated in favor of :func:`pytest_warning_recorded`, and will be removed in a future version. diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 03d8f5394d3..47a7ac2253e 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -2,6 +2,7 @@ import inspect import os import sys +import warnings from collections import defaultdict from collections import deque from types import TracebackType @@ -45,6 +46,7 @@ from _pytest.config import _PluggyPlugin from _pytest.config import Config from _pytest.config.argparsing import Parser +from _pytest.deprecated import FILLFUNCARGS from _pytest.mark import ParameterSet from _pytest.outcomes import fail from _pytest.outcomes import TEST_OUTCOME @@ -359,8 +361,7 @@ def reorder_items_atscope( def fillfixtures(function: "Function") -> None: """Fill missing funcargs for a test function.""" - # Uncomment this after 6.0 release (#7361) - # warnings.warn(FILLFUNCARGS, stacklevel=2) + warnings.warn(FILLFUNCARGS, stacklevel=2) try: request = function._request except AttributeError: diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index e60bfe9f9e4..1906a359871 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -13,6 +13,7 @@ from pluggy import HookspecMarker from _pytest.compat import TYPE_CHECKING +from _pytest.deprecated import WARNING_CAPTURED_HOOK if TYPE_CHECKING: import pdb @@ -723,9 +724,7 @@ def pytest_terminal_summary( """ -# Uncomment this after 6.0 release (#7361) -# @hookspec(historic=True, warn_on_impl=WARNING_CAPTURED_HOOK) -@hookspec(historic=True) +@hookspec(historic=True, warn_on_impl=WARNING_CAPTURED_HOOK) def pytest_warning_captured( warning_message: "warnings.WarningMessage", when: "Literal['config', 'collect', 'runtest']", diff --git a/src/_pytest/mark/__init__.py b/src/_pytest/mark/__init__.py index d677d49c132..6a9b262307e 100644 --- a/src/_pytest/mark/__init__.py +++ b/src/_pytest/mark/__init__.py @@ -1,5 +1,6 @@ """Generic mechanism for marking and selecting python functions.""" import typing +import warnings from typing import AbstractSet from typing import List from typing import Optional @@ -22,6 +23,8 @@ from _pytest.config import hookimpl from _pytest.config import UsageError from _pytest.config.argparsing import Parser +from _pytest.deprecated import MINUS_K_COLON +from _pytest.deprecated import MINUS_K_DASH from _pytest.store import StoreKey if TYPE_CHECKING: @@ -185,14 +188,12 @@ def deselect_by_keyword(items: "List[Item]", config: Config) -> None: if keywordexpr.startswith("-"): # To be removed in pytest 7.0.0. - # Uncomment this after 6.0 release (#7361) - # warnings.warn(MINUS_K_DASH, stacklevel=2) + warnings.warn(MINUS_K_DASH, stacklevel=2) keywordexpr = "not " + keywordexpr[1:] selectuntil = False if keywordexpr[-1:] == ":": # To be removed in pytest 7.0.0. - # Uncomment this after 6.0 release (#7361) - # warnings.warn(MINUS_K_COLON, stacklevel=2) + warnings.warn(MINUS_K_COLON, stacklevel=2) selectuntil = True keywordexpr = keywordexpr[:-1] diff --git a/src/pytest/collect.py b/src/pytest/collect.py index 55b4b9b359c..2edf4470f4d 100644 --- a/src/pytest/collect.py +++ b/src/pytest/collect.py @@ -1,10 +1,11 @@ import sys +import warnings from types import ModuleType from typing import Any from typing import List import pytest - +from _pytest.deprecated import PYTEST_COLLECT_MODULE COLLECT_FAKEMODULE_ATTRIBUTES = [ "Collector", @@ -31,8 +32,7 @@ def __dir__(self) -> List[str]: def __getattr__(self, name: str) -> Any: if name not in self.__all__: raise AttributeError(name) - # Uncomment this after 6.0 release (#7361) - # warnings.warn(PYTEST_COLLECT_MODULE.format(name=name), stacklevel=2) + warnings.warn(PYTEST_COLLECT_MODULE.format(name=name), stacklevel=2) return getattr(pytest, name) diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index d3db792ab3c..eb5d527f52b 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -6,7 +6,6 @@ from _pytest.pytester import Testdir -@pytest.mark.skip(reason="should be reintroduced in 6.1: #7361") @pytest.mark.parametrize("attribute", pytest.collect.__all__) # type: ignore # false positive due to dynamic attribute def test_pytest_collect_module_deprecated(attribute): @@ -24,7 +23,6 @@ def test_external_plugins_integrated(testdir, plugin): testdir.parseconfig("-p", plugin) -@pytest.mark.skip(reason="should be reintroduced in 6.1: #7361") def test_fillfuncargs_is_deprecated() -> None: with pytest.warns( pytest.PytestDeprecationWarning, @@ -33,7 +31,6 @@ def test_fillfuncargs_is_deprecated() -> None: pytest._fillfuncargs(mock.Mock()) -@pytest.mark.skip(reason="should be reintroduced in 6.1: #7361") def test_minus_k_dash_is_deprecated(testdir) -> None: threepass = testdir.makepyfile( test_threepass=""" @@ -46,7 +43,6 @@ def test_three(): assert 1 result.stdout.fnmatch_lines(["*The `-k '-expr'` syntax*deprecated*"]) -@pytest.mark.skip(reason="should be reintroduced in 6.1: #7361") def test_minus_k_colon_is_deprecated(testdir) -> None: threepass = testdir.makepyfile( test_threepass="""