Merge pull request #3274 from feuillemorte/3268-add-deprecation
Added warning when "[pytest]" section is used in a ".cfg" file passed with "-c"
This commit is contained in:
commit
1549d61379
|
@ -1251,7 +1251,7 @@ def getcfg(args, warnfunc=None):
|
||||||
This parameter should be removed when pytest
|
This parameter should be removed when pytest
|
||||||
adopts standard deprecation warnings (#1804).
|
adopts standard deprecation warnings (#1804).
|
||||||
"""
|
"""
|
||||||
from _pytest.deprecated import SETUP_CFG_PYTEST
|
from _pytest.deprecated import CFG_PYTEST_SECTION
|
||||||
inibasenames = ["pytest.ini", "tox.ini", "setup.cfg"]
|
inibasenames = ["pytest.ini", "tox.ini", "setup.cfg"]
|
||||||
args = [x for x in args if not str(x).startswith("-")]
|
args = [x for x in args if not str(x).startswith("-")]
|
||||||
if not args:
|
if not args:
|
||||||
|
@ -1265,7 +1265,7 @@ def getcfg(args, warnfunc=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 warnfunc:
|
if inibasename == 'setup.cfg' and warnfunc:
|
||||||
warnfunc('C1', SETUP_CFG_PYTEST)
|
warnfunc('C1', CFG_PYTEST_SECTION.format(filename=inibasename))
|
||||||
return base, p, iniconfig['pytest']
|
return base, p, iniconfig['pytest']
|
||||||
if inibasename == 'setup.cfg' and 'tool:pytest' in iniconfig.sections:
|
if inibasename == 'setup.cfg' and 'tool:pytest' in iniconfig.sections:
|
||||||
return base, p, iniconfig['tool:pytest']
|
return base, p, iniconfig['tool:pytest']
|
||||||
|
@ -1329,10 +1329,14 @@ def determine_setup(inifile, args, warnfunc=None, rootdir_cmd_arg=None):
|
||||||
if inifile:
|
if inifile:
|
||||||
iniconfig = py.iniconfig.IniConfig(inifile)
|
iniconfig = py.iniconfig.IniConfig(inifile)
|
||||||
is_cfg_file = str(inifile).endswith('.cfg')
|
is_cfg_file = str(inifile).endswith('.cfg')
|
||||||
|
# TODO: [pytest] section in *.cfg files is depricated. Need refactoring.
|
||||||
sections = ['tool:pytest', 'pytest'] if is_cfg_file else ['pytest']
|
sections = ['tool:pytest', 'pytest'] if is_cfg_file else ['pytest']
|
||||||
for section in sections:
|
for section in sections:
|
||||||
try:
|
try:
|
||||||
inicfg = iniconfig[section]
|
inicfg = iniconfig[section]
|
||||||
|
if is_cfg_file and section == 'pytest' and warnfunc:
|
||||||
|
from _pytest.deprecated import CFG_PYTEST_SECTION
|
||||||
|
warnfunc('C1', CFG_PYTEST_SECTION.format(filename=str(inifile)))
|
||||||
break
|
break
|
||||||
except KeyError:
|
except KeyError:
|
||||||
inicfg = None
|
inicfg = None
|
||||||
|
|
|
@ -22,7 +22,7 @@ FUNCARG_PREFIX = (
|
||||||
'and scheduled to be removed in pytest 4.0. '
|
'and scheduled to be removed in pytest 4.0. '
|
||||||
'Please remove the prefix and use the @pytest.fixture decorator instead.')
|
'Please remove the prefix and use the @pytest.fixture decorator instead.')
|
||||||
|
|
||||||
SETUP_CFG_PYTEST = '[pytest] section in setup.cfg files is deprecated, use [tool:pytest] instead.'
|
CFG_PYTEST_SECTION = '[pytest] section in {filename} files is deprecated, use [tool:pytest] instead.'
|
||||||
|
|
||||||
GETFUNCARGVALUE = "use of getfuncargvalue is deprecated, use getfixturevalue"
|
GETFUNCARGVALUE = "use of getfuncargvalue is deprecated, use getfixturevalue"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Added warning when ``[pytest]`` section is used in a ``.cfg`` file passed with ``-c``
|
|
@ -48,6 +48,15 @@ def test_pytest_setup_cfg_deprecated(testdir):
|
||||||
result.stdout.fnmatch_lines(['*pytest*section in setup.cfg files is deprecated*use*tool:pytest*instead*'])
|
result.stdout.fnmatch_lines(['*pytest*section in setup.cfg files is deprecated*use*tool:pytest*instead*'])
|
||||||
|
|
||||||
|
|
||||||
|
def test_pytest_custom_cfg_deprecated(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*'])
|
||||||
|
|
||||||
|
|
||||||
def test_str_args_deprecated(tmpdir, testdir):
|
def test_str_args_deprecated(tmpdir, testdir):
|
||||||
"""Deprecate passing strings to pytest.main(). Scheduled for removal in pytest-4.0."""
|
"""Deprecate passing strings to pytest.main(). Scheduled for removal in pytest-4.0."""
|
||||||
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
||||||
|
|
Loading…
Reference in New Issue