Skip to content

Commit bc666a8

Browse files
fix issue #3523 - deprecate using setup.cfg
1 parent 0dbe144 commit bc666a8

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
# You want to make some `__init__` or function "private".
9399
#

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(
@@ -1311,7 +1325,12 @@ def test_simple_noini(self, tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
13111325
"pyproject.toml", "[tool.pytest.ini_options]\nx=10", id="pyproject.toml"
13121326
),
13131327
pytest.param("tox.ini", "[pytest]\nx=10", id="tox.ini"),
1314-
pytest.param("setup.cfg", "[tool:pytest]\nx=10", id="setup.cfg"),
1328+
pytest.param(
1329+
"setup.cfg",
1330+
"[tool:pytest]\nx=10",
1331+
id="setup.cfg",
1332+
marks=setup_cfg_nowarn,
1333+
),
13151334
],
13161335
)
13171336
def test_with_ini(self, tmp_path: Path, name: str, contents: str) -> None:
@@ -1424,6 +1443,7 @@ def test_with_existing_file_in_subdir(
14241443
assert rootpath == tmp_path
14251444
assert inipath is None
14261445

1446+
@setup_cfg_nowarn
14271447
def test_with_config_also_in_parent_directory(
14281448
self, tmp_path: Path, monkeypatch: MonkeyPatch
14291449
) -> None:
@@ -1441,7 +1461,10 @@ def test_with_config_also_in_parent_directory(
14411461

14421462

14431463
class TestOverrideIniArgs:
1444-
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
1464+
@pytest.mark.parametrize(
1465+
"name",
1466+
[pytest.param("setup.cfg", marks=setup_cfg_nowarn), "tox.ini", "pytest.ini"],
1467+
)
14451468
def test_override_ini_names(self, pytester: Pytester, name: str) -> None:
14461469
section = "[pytest]" if name != "setup.cfg" else "[tool:pytest]"
14471470
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)