fix issue #3523 - deprecate using setup.cfg
This commit is contained in:
parent
4c3d797db9
commit
17514c15db
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import warnings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
@ -11,6 +12,7 @@ from typing import TYPE_CHECKING
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from .exceptions import UsageError
|
from .exceptions import UsageError
|
||||||
|
from _pytest.deprecated import SETUP_CFG_CONFIG
|
||||||
from _pytest.outcomes import fail
|
from _pytest.outcomes import fail
|
||||||
from _pytest.pathlib import absolutepath
|
from _pytest.pathlib import absolutepath
|
||||||
from _pytest.pathlib import commonpath
|
from _pytest.pathlib import commonpath
|
||||||
|
@ -70,6 +72,11 @@ def _parse_cfg_file(path: Path) -> PARSE_RESULT:
|
||||||
iniconfig = _parse_ini_config(path)
|
iniconfig = _parse_ini_config(path)
|
||||||
|
|
||||||
if "tool:pytest" in iniconfig.sections:
|
if "tool:pytest" in iniconfig.sections:
|
||||||
|
|
||||||
|
if path.name == "setup.cfg":
|
||||||
|
warnings.warn_explicit(
|
||||||
|
SETUP_CFG_CONFIG, None, os.fspath(path), 0, module="pytest"
|
||||||
|
)
|
||||||
return dict(iniconfig["tool:pytest"].items())
|
return dict(iniconfig["tool:pytest"].items())
|
||||||
elif "pytest" in iniconfig.sections:
|
elif "pytest" in iniconfig.sections:
|
||||||
# If a setup.cfg contains a "[pytest]" section, we raise a failure to indicate users that
|
# If a setup.cfg contains a "[pytest]" section, we raise a failure to indicate users that
|
||||||
|
|
|
@ -66,6 +66,12 @@ ARGUMENT_TYPE_STR = UnformattedWarning(
|
||||||
" (options: {names})",
|
" (options: {names})",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SETUP_CFG_CONFIG = PytestDeprecationWarning(
|
||||||
|
"configuring pytest in setup.cfg has been deprecated \n"
|
||||||
|
"as pytest and setuptools do not share he same config parser\n"
|
||||||
|
"please consider pytest.ini/tox.ini or pyproject.toml"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
HOOK_LEGACY_PATH_ARG = UnformattedWarning(
|
HOOK_LEGACY_PATH_ARG = UnformattedWarning(
|
||||||
PytestRemovedIn8Warning,
|
PytestRemovedIn8Warning,
|
||||||
|
|
|
@ -31,9 +31,18 @@ from _pytest.pathlib import absolutepath
|
||||||
from _pytest.pytester import Pytester
|
from _pytest.pytester import Pytester
|
||||||
|
|
||||||
|
|
||||||
|
setup_cfg_nowarn = pytest.mark.filterwarnings(
|
||||||
|
"ignore:.*setup.cfg.*:pytest.PytestDeprecationWarning"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestParseIni:
|
class TestParseIni:
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"section, filename", [("pytest", "pytest.ini"), ("tool:pytest", "setup.cfg")]
|
"section, filename",
|
||||||
|
[
|
||||||
|
("pytest", "pytest.ini"),
|
||||||
|
pytest.param("tool:pytest", "setup.cfg", marks=setup_cfg_nowarn),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
def test_getcfg_and_config(
|
def test_getcfg_and_config(
|
||||||
self,
|
self,
|
||||||
|
@ -62,6 +71,7 @@ class TestParseIni:
|
||||||
config = pytester.parseconfigure(str(sub))
|
config = pytester.parseconfigure(str(sub))
|
||||||
assert config.inicfg["name"] == "value"
|
assert config.inicfg["name"] == "value"
|
||||||
|
|
||||||
|
@setup_cfg_nowarn
|
||||||
def test_setupcfg_uses_toolpytest_with_pytest(self, pytester: Pytester) -> None:
|
def test_setupcfg_uses_toolpytest_with_pytest(self, pytester: Pytester) -> None:
|
||||||
p1 = pytester.makepyfile("def test(): pass")
|
p1 = pytester.makepyfile("def test(): pass")
|
||||||
pytester.makefile(
|
pytester.makefile(
|
||||||
|
@ -113,7 +123,7 @@ class TestParseIni:
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"section, name",
|
"section, name",
|
||||||
[
|
[
|
||||||
("tool:pytest", "setup.cfg"),
|
pytest.param("tool:pytest", "setup.cfg", marks=setup_cfg_nowarn),
|
||||||
("pytest", "tox.ini"),
|
("pytest", "tox.ini"),
|
||||||
("pytest", "pytest.ini"),
|
("pytest", "pytest.ini"),
|
||||||
("pytest", ".pytest.ini"),
|
("pytest", ".pytest.ini"),
|
||||||
|
@ -1355,7 +1365,12 @@ class TestRootdir:
|
||||||
"pyproject.toml", "[tool.pytest.ini_options]\nx=10", id="pyproject.toml"
|
"pyproject.toml", "[tool.pytest.ini_options]\nx=10", id="pyproject.toml"
|
||||||
),
|
),
|
||||||
pytest.param("tox.ini", "[pytest]\nx=10", id="tox.ini"),
|
pytest.param("tox.ini", "[pytest]\nx=10", id="tox.ini"),
|
||||||
pytest.param("setup.cfg", "[tool:pytest]\nx=10", id="setup.cfg"),
|
pytest.param(
|
||||||
|
"setup.cfg",
|
||||||
|
"[tool:pytest]\nx=10",
|
||||||
|
id="setup.cfg",
|
||||||
|
marks=setup_cfg_nowarn,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_with_ini(self, tmp_path: Path, name: str, contents: str) -> None:
|
def test_with_ini(self, tmp_path: Path, name: str, contents: str) -> None:
|
||||||
|
@ -1488,6 +1503,7 @@ class TestRootdir:
|
||||||
assert rootpath == tmp_path
|
assert rootpath == tmp_path
|
||||||
assert inipath is None
|
assert inipath is None
|
||||||
|
|
||||||
|
@setup_cfg_nowarn
|
||||||
def test_with_config_also_in_parent_directory(
|
def test_with_config_also_in_parent_directory(
|
||||||
self, tmp_path: Path, monkeypatch: MonkeyPatch
|
self, tmp_path: Path, monkeypatch: MonkeyPatch
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -1505,7 +1521,10 @@ class TestRootdir:
|
||||||
|
|
||||||
|
|
||||||
class TestOverrideIniArgs:
|
class TestOverrideIniArgs:
|
||||||
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
|
@pytest.mark.parametrize(
|
||||||
|
"name",
|
||||||
|
[pytest.param("setup.cfg", marks=setup_cfg_nowarn), "tox.ini", "pytest.ini"],
|
||||||
|
)
|
||||||
def test_override_ini_names(self, pytester: Pytester, name: str) -> None:
|
def test_override_ini_names(self, pytester: Pytester, name: str) -> None:
|
||||||
section = "[pytest]" if name != "setup.cfg" else "[tool:pytest]"
|
section = "[pytest]" if name != "setup.cfg" else "[tool:pytest]"
|
||||||
pytester.path.joinpath(name).write_text(
|
pytester.path.joinpath(name).write_text(
|
||||||
|
|
|
@ -122,6 +122,7 @@ def test_ini_markers_whitespace(pytester: Pytester) -> None:
|
||||||
rec.assertoutcome(passed=1)
|
rec.assertoutcome(passed=1)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.filterwarnings("ignore:.*setup.cfg.*:pytest.PytestDeprecationWarning")
|
||||||
def test_marker_without_description(pytester: Pytester) -> None:
|
def test_marker_without_description(pytester: Pytester) -> None:
|
||||||
pytester.makefile(
|
pytester.makefile(
|
||||||
".cfg",
|
".cfg",
|
||||||
|
|
Loading…
Reference in New Issue