Remove support for '[pytest]' section in setup.cfg file

Fix #3086
This commit is contained in:
Bruno Oliveira 2018-12-19 17:43:17 -02:00
parent c400d8b2d8
commit 9138419379
5 changed files with 27 additions and 41 deletions

View File

@ -0,0 +1,4 @@
``[pytest]`` section in **setup.cfg** files is not longer supported, use ``[tool:pytest]`` instead. ``setup.cfg`` files
are meant for use with ``distutils``, and a section named ``pytest`` has notoriously been a source of conflicts and bugs.
Note that for **pytest.ini** and **tox.ini** files the section remains ``[pytest]``.

View File

@ -125,15 +125,6 @@ To update the code, use ``pytest.param``:
[pytest] section in setup.cfg files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.0
``[pytest]`` sections in ``setup.cfg`` files should now be named ``[tool:pytest]``
to avoid conflicts with other distutils commands.
Result log (``--result-log``) Result log (``--result-log``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -185,6 +176,16 @@ Switch over to the ``@pytest.fixture`` decorator:
return SomeData() return SomeData()
[pytest] section in setup.cfg files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Removed in version 4.0.*
``[pytest]`` sections in ``setup.cfg`` files should now be named ``[tool:pytest]``
to avoid conflicts with other distutils commands.
Metafunc.addcall Metafunc.addcall
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~

View File

@ -3,6 +3,7 @@ import os
import py import py
from .exceptions import UsageError from .exceptions import UsageError
from _pytest.outcomes import fail
def exists(path, ignore=EnvironmentError): def exists(path, ignore=EnvironmentError):
@ -34,15 +35,10 @@ def getcfg(args, config=None):
iniconfig = py.iniconfig.IniConfig(p) iniconfig = py.iniconfig.IniConfig(p)
if "pytest" in iniconfig.sections: if "pytest" in iniconfig.sections:
if inibasename == "setup.cfg" and config is not None: if inibasename == "setup.cfg" and config is not None:
from _pytest.warnings import _issue_warning_captured
from _pytest.warning_types import RemovedInPytest4Warning
_issue_warning_captured( fail(
RemovedInPytest4Warning( CFG_PYTEST_SECTION.format(filename=inibasename),
CFG_PYTEST_SECTION.format(filename=inibasename) pytrace=False,
),
hook=config.hook,
stacklevel=2,
) )
return base, p, iniconfig["pytest"] return base, p, iniconfig["pytest"]
if ( if (
@ -112,14 +108,9 @@ def determine_setup(inifile, args, rootdir_cmd_arg=None, config=None):
inicfg = iniconfig[section] inicfg = iniconfig[section]
if is_cfg_file and section == "pytest" and config is not None: if is_cfg_file and section == "pytest" and config is not None:
from _pytest.deprecated import CFG_PYTEST_SECTION from _pytest.deprecated import CFG_PYTEST_SECTION
from _pytest.warnings import _issue_warning_captured
# TODO: [pytest] section in *.cfg files is deprecated. Need refactoring once fail(
# the deprecation expires. CFG_PYTEST_SECTION.format(filename=str(inifile)), pytrace=False
_issue_warning_captured(
CFG_PYTEST_SECTION.format(filename=str(inifile)),
config.hook,
stacklevel=2,
) )
break break
except KeyError: except KeyError:

View File

@ -14,7 +14,6 @@ from __future__ import print_function
from _pytest.warning_types import PytestDeprecationWarning from _pytest.warning_types import PytestDeprecationWarning
from _pytest.warning_types import RemovedInPytest4Warning from _pytest.warning_types import RemovedInPytest4Warning
from _pytest.warning_types import UnformattedWarning
YIELD_TESTS = "yield tests were removed in pytest 4.0 - {name} will be ignored" YIELD_TESTS = "yield tests were removed in pytest 4.0 - {name} will be ignored"
@ -31,10 +30,7 @@ FIXTURE_NAMED_REQUEST = PytestDeprecationWarning(
"'request' is a reserved name for fixtures and will raise an error in future versions" "'request' is a reserved name for fixtures and will raise an error in future versions"
) )
CFG_PYTEST_SECTION = UnformattedWarning( CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead."
RemovedInPytest4Warning,
"[pytest] section in {filename} files is deprecated, use [tool:pytest] instead.",
)
GETFUNCARGVALUE = RemovedInPytest4Warning( GETFUNCARGVALUE = RemovedInPytest4Warning(
"getfuncargvalue is deprecated, use getfixturevalue" "getfuncargvalue is deprecated, use getfixturevalue"

View File

@ -10,8 +10,7 @@ from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
pytestmark = pytest.mark.pytester_example_path("deprecated") pytestmark = pytest.mark.pytester_example_path("deprecated")
@pytest.mark.filterwarnings("default") def test_pytest_setup_cfg_unsupported(testdir):
def test_pytest_setup_cfg_deprecated(testdir):
testdir.makefile( testdir.makefile(
".cfg", ".cfg",
setup=""" setup="""
@ -19,14 +18,11 @@ def test_pytest_setup_cfg_deprecated(testdir):
addopts = --verbose addopts = --verbose
""", """,
) )
result = testdir.runpytest() with pytest.raises(pytest.fail.Exception):
result.stdout.fnmatch_lines( testdir.runpytest()
["*pytest*section in setup.cfg files is deprecated*use*tool:pytest*instead*"]
)
@pytest.mark.filterwarnings("default") def test_pytest_custom_cfg_unsupported(testdir):
def test_pytest_custom_cfg_deprecated(testdir):
testdir.makefile( testdir.makefile(
".cfg", ".cfg",
custom=""" custom="""
@ -34,10 +30,8 @@ def test_pytest_custom_cfg_deprecated(testdir):
addopts = --verbose addopts = --verbose
""", """,
) )
result = testdir.runpytest("-c", "custom.cfg") with pytest.raises(pytest.fail.Exception):
result.stdout.fnmatch_lines( testdir.runpytest("-c", "custom.cfg")
["*pytest*section in custom.cfg files is deprecated*use*tool:pytest*instead*"]
)
def test_getfuncargvalue_is_deprecated(request): def test_getfuncargvalue_is_deprecated(request):