Skip to content

Commit 5bb035a

Browse files
fix issue #3523 - deprecate using setup.cfg
1 parent 4a72924 commit 5bb035a

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

src/_pytest/config/findpaths.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import warnings
23
from pathlib import Path
34
from typing import Dict
45
from typing import Iterable
@@ -10,6 +11,7 @@
1011
from typing import Union
1112

1213
from .exceptions import UsageError
14+
from _pytest.deprecated import SETUP_CFG_CONFIG
1315
from _pytest.outcomes import fail
1416
from _pytest.pathlib import absolutepath
1517
from _pytest.pathlib import commonpath
@@ -69,6 +71,11 @@ def _parse_cfg_file(path: Path) -> PARSE_RESULT:
6971
iniconfig = _parse_ini_config(path)
7072

7173
if "tool:pytest" in iniconfig.sections:
74+
75+
if path.name == "setup.cfg":
76+
warnings.warn_explicit(
77+
SETUP_CFG_CONFIG, None, os.fspath(path), 0, module="pytest"
78+
)
7279
return dict(iniconfig["tool:pytest"].items())
7380
elif "pytest" in iniconfig.sections:
7481
# If a setup.cfg contains a "[pytest]" section, we raise a failure to indicate users that

src/_pytest/deprecated.py

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@
8888
" (options: {names})",
8989
)
9090

91+
SETUP_CFG_CONFIG = PytestDeprecationWarning(
92+
"configuring pytest in setup.cfg has been deprecated \n"
93+
"as pytest and setuptools do not share he same config parser\n"
94+
"please consider pytest.ini/tox.ini or pyproject.toml"
95+
)
96+
9197

9298
NODE_FSPATH = UnformattedWarning(
9399
PytestDeprecationWarning,

testing/test_config.py

+27-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,18 @@
3131
from _pytest.pytester import Pytester
3232

3333

34+
setup_cfg_nowarn = pytest.mark.filterwarnings(
35+
"ignore:.*setup.cfg.*:pytest.PytestDeprecationWarning"
36+
)
37+
38+
3439
class TestParseIni:
3540
@pytest.mark.parametrize(
36-
"section, filename", [("pytest", "pytest.ini"), ("tool:pytest", "setup.cfg")]
41+
"section, filename",
42+
[
43+
("pytest", "pytest.ini"),
44+
pytest.param("tool:pytest", "setup.cfg", marks=setup_cfg_nowarn),
45+
],
3746
)
3847
def test_getcfg_and_config(
3948
self,
@@ -62,6 +71,7 @@ def test_getcfg_and_config(
6271
config = pytester.parseconfigure(str(sub))
6372
assert config.inicfg["name"] == "value"
6473

74+
@setup_cfg_nowarn
6575
def test_setupcfg_uses_toolpytest_with_pytest(self, pytester: Pytester) -> None:
6676
p1 = pytester.makepyfile("def test(): pass")
6777
pytester.makefile(
@@ -112,7 +122,11 @@ def test_tox_ini_wrong_version(self, pytester: Pytester) -> None:
112122

113123
@pytest.mark.parametrize(
114124
"section, name",
115-
[("tool:pytest", "setup.cfg"), ("pytest", "tox.ini"), ("pytest", "pytest.ini")],
125+
[
126+
pytest.param("tool:pytest", "setup.cfg", marks=setup_cfg_nowarn),
127+
("pytest", "tox.ini"),
128+
("pytest", "pytest.ini"),
129+
],
116130
)
117131
def test_ini_names(self, pytester: Pytester, name, section) -> None:
118132
pytester.path.joinpath(name).write_text(
@@ -1331,7 +1345,12 @@ def test_simple_noini(self, tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
13311345
"pyproject.toml", "[tool.pytest.ini_options]\nx=10", id="pyproject.toml"
13321346
),
13331347
pytest.param("tox.ini", "[pytest]\nx=10", id="tox.ini"),
1334-
pytest.param("setup.cfg", "[tool:pytest]\nx=10", id="setup.cfg"),
1348+
pytest.param(
1349+
"setup.cfg",
1350+
"[tool:pytest]\nx=10",
1351+
id="setup.cfg",
1352+
marks=setup_cfg_nowarn,
1353+
),
13351354
],
13361355
)
13371356
def test_with_ini(self, tmp_path: Path, name: str, contents: str) -> None:
@@ -1464,6 +1483,7 @@ def test_with_existing_file_in_subdir(
14641483
assert rootpath == tmp_path
14651484
assert inipath is None
14661485

1486+
@setup_cfg_nowarn
14671487
def test_with_config_also_in_parent_directory(
14681488
self, tmp_path: Path, monkeypatch: MonkeyPatch
14691489
) -> None:
@@ -1481,7 +1501,10 @@ def test_with_config_also_in_parent_directory(
14811501

14821502

14831503
class TestOverrideIniArgs:
1484-
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
1504+
@pytest.mark.parametrize(
1505+
"name",
1506+
[pytest.param("setup.cfg", marks=setup_cfg_nowarn), "tox.ini", "pytest.ini"],
1507+
)
14851508
def test_override_ini_names(self, pytester: Pytester, name: str) -> None:
14861509
section = "[pytest]" if name != "setup.cfg" else "[tool:pytest]"
14871510
pytester.path.joinpath(name).write_text(

testing/test_mark.py

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def test_markers():
123123
rec.assertoutcome(passed=1)
124124

125125

126+
@pytest.mark.filterwarnings("ignore:.*setup.cfg.*:pytest.PytestDeprecationWarning")
126127
def test_marker_without_description(pytester: Pytester) -> None:
127128
pytester.makefile(
128129
".cfg",

0 commit comments

Comments
 (0)