Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3260 fix pytest section #3267

Merged
merged 6 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,10 +1327,18 @@ def determine_setup(inifile, args, warnfunc=None):
dirs = get_dirs_from_args(args)
if inifile:
iniconfig = py.iniconfig.IniConfig(inifile)
try:
inicfg = iniconfig["pytest"]
except KeyError:
inicfg = None
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']
for section in sections:
try:
inicfg = iniconfig[section]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we never deprecated [pytest] in custom configs, i believe we should either support both or target the features branch

Copy link
Contributor Author

@feuillemorte feuillemorte Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RonnyPfannschmidt fixed

I thought that #3086 deprecates [pytest] section in custom configs too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@feuillemorte it is deprecated, but we will remove it only in 4.0. We should start issuing warnings here as well if users are using [pytest] in setup.cfg files, see:

pytest/_pytest/config.py

Lines 1266 to 1267 in 2008554

if inibasename == 'setup.cfg' and warnfunc:
warnfunc('C1', SETUP_CFG_PYTEST)

But we don't introduce new warnings in bug-fixes (we've broken test suites in the past because of that) so the introduction of this warning should be done in features, in a separate task.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #3268 with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicoddemus I see, thanks!

if is_cfg_file and section == 'pytest' and warnfunc:
from _pytest.deprecated import SETUP_CFG_PYTEST
warnfunc('C1', SETUP_CFG_PYTEST.replace('setup.cfg', str(inifile)))
break
except KeyError:
inicfg = None
rootdir = get_common_ancestor(dirs)
else:
ancestor = get_common_ancestor(dirs)
Expand Down
1 change: 1 addition & 0 deletions changelog/3260.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed ``tool:pytest`` section when setup.cfg passed by option ``-c``
7 changes: 7 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ def pytest_addoption(parser):
config = testdir.parseconfig("-c", "custom.cfg")
assert config.getini("custom") == "1"

testdir.makefile(".cfg", custom_tool_pytest_section="""
[tool:pytest]
custom = 1
""")
config = testdir.parseconfig("-c", "custom_tool_pytest_section.cfg")
assert config.getini("custom") == "1"

def test_absolute_win32_path(self, testdir):
temp_cfg_file = testdir.makefile(".cfg", custom="""
[pytest]
Expand Down