Skip to content

Commit

Permalink
Remove support for '[pytest]' section in setup.cfg file
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Dec 19, 2018
1 parent c400d8b commit 9138419
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 43 deletions.
4 changes: 4 additions & 0 deletions changelog/3086.removal.rst
Original file line number Diff line number Diff line change
@@ -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]``.
19 changes: 10 additions & 9 deletions doc/en/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -185,6 +176,16 @@ Switch over to the ``@pytest.fixture`` decorator:
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
~~~~~~~~~~~~~~~~

Expand Down
25 changes: 8 additions & 17 deletions src/_pytest/config/findpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import py

from .exceptions import UsageError
from _pytest.outcomes import fail


def exists(path, ignore=EnvironmentError):
Expand Down Expand Up @@ -34,15 +35,10 @@ def getcfg(args, config=None):
iniconfig = py.iniconfig.IniConfig(p)
if "pytest" in iniconfig.sections:
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(
RemovedInPytest4Warning(
CFG_PYTEST_SECTION.format(filename=inibasename)
),
hook=config.hook,
stacklevel=2,

fail(
CFG_PYTEST_SECTION.format(filename=inibasename),
pytrace=False,
)
return base, p, iniconfig["pytest"]
if (
Expand Down Expand Up @@ -112,14 +108,9 @@ def determine_setup(inifile, args, rootdir_cmd_arg=None, config=None):
inicfg = iniconfig[section]
if is_cfg_file and section == "pytest" and config is not None:
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
# the deprecation expires.
_issue_warning_captured(
CFG_PYTEST_SECTION.format(filename=str(inifile)),
config.hook,
stacklevel=2,

fail(
CFG_PYTEST_SECTION.format(filename=str(inifile)), pytrace=False
)
break
except KeyError:
Expand Down
6 changes: 1 addition & 5 deletions src/_pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from _pytest.warning_types import PytestDeprecationWarning
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"
Expand All @@ -31,10 +30,7 @@
"'request' is a reserved name for fixtures and will raise an error in future versions"
)

CFG_PYTEST_SECTION = UnformattedWarning(
RemovedInPytest4Warning,
"[pytest] section in {filename} files is deprecated, use [tool:pytest] instead.",
)
CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead."

GETFUNCARGVALUE = RemovedInPytest4Warning(
"getfuncargvalue is deprecated, use getfixturevalue"
Expand Down
18 changes: 6 additions & 12 deletions testing/deprecated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,28 @@
pytestmark = pytest.mark.pytester_example_path("deprecated")


@pytest.mark.filterwarnings("default")
def test_pytest_setup_cfg_deprecated(testdir):
def test_pytest_setup_cfg_unsupported(testdir):
testdir.makefile(
".cfg",
setup="""
[pytest]
addopts = --verbose
""",
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(
["*pytest*section in setup.cfg files is deprecated*use*tool:pytest*instead*"]
)
with pytest.raises(pytest.fail.Exception):
testdir.runpytest()


@pytest.mark.filterwarnings("default")
def test_pytest_custom_cfg_deprecated(testdir):
def test_pytest_custom_cfg_unsupported(testdir):
testdir.makefile(
".cfg",
custom="""
[pytest]
addopts = --verbose
""",
)
result = testdir.runpytest("-c", "custom.cfg")
result.stdout.fnmatch_lines(
["*pytest*section in custom.cfg files is deprecated*use*tool:pytest*instead*"]
)
with pytest.raises(pytest.fail.Exception):
testdir.runpytest("-c", "custom.cfg")


def test_getfuncargvalue_is_deprecated(request):
Expand Down

0 comments on commit 9138419

Please sign in to comment.