From f2b7809d5d2c04afc3f04f6989e0b327ca753b88 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 30 Jun 2019 12:18:14 -0300 Subject: [PATCH] Move setup.cfg error message and tests to an appropriate location Those are not really deprecated anymore and are part of the normal code for config --- src/_pytest/config/findpaths.py | 7 +++---- src/_pytest/deprecated.py | 2 -- testing/deprecated_test.py | 24 ------------------------ testing/test_config.py | 24 ++++++++++++++++++++++++ 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index fa2024470..abb248b1d 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -20,8 +20,6 @@ def getcfg(args, config=None): note: config is optional and used only to issue warnings explicitly (#2891). """ - from _pytest.deprecated import CFG_PYTEST_SECTION - inibasenames = ["pytest.ini", "tox.ini", "setup.cfg"] args = [x for x in args if not str(x).startswith("-")] if not args: @@ -97,6 +95,9 @@ def get_dirs_from_args(args): return [get_dir_from_path(path) for path in possible_paths if path.exists()] +CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead." + + def determine_setup(inifile, args, rootdir_cmd_arg=None, config=None): dirs = get_dirs_from_args(args) if inifile: @@ -107,8 +108,6 @@ def determine_setup(inifile, args, rootdir_cmd_arg=None, config=None): try: inicfg = iniconfig[section] if is_cfg_file and section == "pytest" and config is not None: - from _pytest.deprecated import CFG_PYTEST_SECTION - fail( CFG_PYTEST_SECTION.format(filename=str(inifile)), pytrace=False ) diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 2598b2a9c..0cce0efb2 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -33,8 +33,6 @@ FIXTURE_NAMED_REQUEST = PytestDeprecationWarning( "'request' is a reserved name for fixtures and will raise an error in future versions" ) -CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead." - FUNCARGNAMES = PytestDeprecationWarning( "The `funcargnames` attribute was an alias for `fixturenames`, " diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 1730e740a..e4a8f72bc 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -4,30 +4,6 @@ from _pytest import deprecated pytestmark = pytest.mark.pytester_example_path("deprecated") -def test_pytest_setup_cfg_unsupported(testdir): - testdir.makefile( - ".cfg", - setup=""" - [pytest] - addopts = --verbose - """, - ) - with pytest.raises(pytest.fail.Exception): - testdir.runpytest() - - -def test_pytest_custom_cfg_unsupported(testdir): - testdir.makefile( - ".cfg", - custom=""" - [pytest] - addopts = --verbose - """, - ) - with pytest.raises(pytest.fail.Exception): - testdir.runpytest("-c", "custom.cfg") - - @pytest.mark.filterwarnings("default") def test_resultlog_is_deprecated(testdir): result = testdir.runpytest("--help") diff --git a/testing/test_config.py b/testing/test_config.py index 76202ca33..9533144e7 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -1245,6 +1245,30 @@ def test_config_blocked_default_plugins(testdir, plugin): assert result.stdout.lines == [""] +class TestSetupCfg: + def test_pytest_setup_cfg_unsupported(self, testdir): + testdir.makefile( + ".cfg", + setup=""" + [pytest] + addopts = --verbose + """, + ) + with pytest.raises(pytest.fail.Exception): + testdir.runpytest() + + def test_pytest_custom_cfg_unsupported(self, testdir): + testdir.makefile( + ".cfg", + custom=""" + [pytest] + addopts = --verbose + """, + ) + with pytest.raises(pytest.fail.Exception): + testdir.runpytest("-c", "custom.cfg") + + class TestPytestPluginsVariable: def test_pytest_plugins_in_non_top_level_conftest_unsupported(self, testdir): testdir.makepyfile(