From 7e58defc15e92d6f5af2c3bd5367b4ec877c8086 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 30 Jun 2019 12:24:51 -0300 Subject: [PATCH] Remove 'pytest.config' --- changelog/5180.removal.rst | 2 ++ doc/en/deprecations.rst | 25 ++++++++++++------------- src/_pytest/deprecated.py | 5 ----- src/_pytest/main.py | 22 ---------------------- testing/test_pytester.py | 3 +-- 5 files changed, 15 insertions(+), 42 deletions(-) diff --git a/changelog/5180.removal.rst b/changelog/5180.removal.rst index e72b76d5a..49f896f94 100644 --- a/changelog/5180.removal.rst +++ b/changelog/5180.removal.rst @@ -11,6 +11,8 @@ removed: syntax. This might change the exception message from previous versions, but they still raise ``TypeError`` on unknown keyword arguments as before. +* ``pytest.config`` global variable. + For more information consult `Deprecations and Removals `__ in the docs. diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index c97061f09..052ab836a 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -34,19 +34,6 @@ in places where we or plugin authors must distinguish between fixture names and names supplied by non-fixture things such as ``pytest.mark.parametrize``. - - -``pytest.config`` global -~~~~~~~~~~~~~~~~~~~~~~~~ - -.. deprecated:: 4.1 - -The ``pytest.config`` global object is deprecated. Instead use -``request.config`` (via the ``request`` fixture) or if you are a plugin author -use the ``pytest_configure(config)`` hook. Note that many hooks can also access -the ``config`` object indirectly, through ``session.config`` or ``item.config`` for example. - - Result log (``--result-log``) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -63,6 +50,7 @@ stable. The actual alternative is still being discussed in issue `#4488 `__. + Removed Features ---------------- @@ -70,6 +58,17 @@ As stated in our :ref:`backwards-compatibility` policy, deprecated features are an appropriate period of deprecation has passed. +``pytest.config`` global +~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionremoved:: 5.0 + +The ``pytest.config`` global object is deprecated. Instead use +``request.config`` (via the ``request`` fixture) or if you are a plugin author +use the ``pytest_configure(config)`` hook. Note that many hooks can also access +the ``config`` object indirectly, through ``session.config`` or ``item.config`` for example. + + .. _`raises message deprecated`: ``"message"`` parameter of ``pytest.raises`` diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 0cce0efb2..2c853d48b 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -46,11 +46,6 @@ RESULT_LOG = PytestDeprecationWarning( ) -PYTEST_CONFIG_GLOBAL = PytestDeprecationWarning( - "the `pytest.config` global is deprecated. Please use `request.config` " - "or `pytest_configure` (if you're a pytest plugin) instead." -) - PYTEST_ENSURETEMP = RemovedInPytest4Warning( "pytest/tmpdir_factory.ensuretemp is deprecated, \n" "please use the tmp_path fixture or tmp_path_factory.mktemp" diff --git a/src/_pytest/main.py b/src/_pytest/main.py index f28bc68db..a5283d737 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -5,7 +5,6 @@ import functools import importlib import os import sys -import warnings import attr import py @@ -15,7 +14,6 @@ from _pytest import nodes from _pytest.config import directory_arg from _pytest.config import hookimpl from _pytest.config import UsageError -from _pytest.deprecated import PYTEST_CONFIG_GLOBAL from _pytest.outcomes import exit from _pytest.runner import collect_one_node @@ -179,26 +177,6 @@ def pytest_addoption(parser): ) -class _ConfigDeprecated: - def __init__(self, config): - self.__dict__["_config"] = config - - def __getattr__(self, attr): - warnings.warn(PYTEST_CONFIG_GLOBAL, stacklevel=2) - return getattr(self._config, attr) - - def __setattr__(self, attr, val): - warnings.warn(PYTEST_CONFIG_GLOBAL, stacklevel=2) - return setattr(self._config, attr, val) - - def __repr__(self): - return "{}({!r})".format(type(self).__name__, self._config) - - -def pytest_configure(config): - __import__("pytest").config = _ConfigDeprecated(config) # compatibility - - def wrap_session(config, doit): """Skeleton command line program""" session = Session(config) diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 37b63f31a..f115ad3d0 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -72,8 +72,7 @@ def test_make_hook_recorder(testdir): def test_parseconfig(testdir): config1 = testdir.parseconfig() config2 = testdir.parseconfig() - assert config2 != config1 - assert config1 != pytest.config + assert config2 is not config1 def test_testdir_runs_with_plugin(testdir):