@@ -10,15 +10,12 @@ def exists(path, ignore=EnvironmentError):
10
10
return False
11
11
12
12
13
- def getcfg (args ):
13
+ def getcfg (args , config = None ):
14
14
"""
15
15
Search the list of arguments for a valid ini-file for pytest,
16
16
and return a tuple of (rootdir, inifile, cfg-dict).
17
17
18
- note: warnfunc is an optional function used to warn
19
- about ini-files that use deprecated features.
20
- This parameter should be removed when pytest
21
- adopts standard deprecation warnings (#1804).
18
+ note: config is optional and used only to issue warnings explicitly (#2891).
22
19
"""
23
20
from _pytest .deprecated import CFG_PYTEST_SECTION
24
21
@@ -34,13 +31,15 @@ def getcfg(args):
34
31
if exists (p ):
35
32
iniconfig = py .iniconfig .IniConfig (p )
36
33
if "pytest" in iniconfig .sections :
37
- if inibasename == "setup.cfg" :
38
- import warnings
34
+ if inibasename == "setup.cfg" and config is not None :
35
+ from _pytest . warnings import _issue_config_warning
39
36
from _pytest .warning_types import RemovedInPytest4Warning
40
37
41
- warnings .warn (
42
- CFG_PYTEST_SECTION .format (filename = inibasename ),
43
- RemovedInPytest4Warning ,
38
+ _issue_config_warning (
39
+ RemovedInPytest4Warning (
40
+ CFG_PYTEST_SECTION .format (filename = inibasename )
41
+ ),
42
+ config = config ,
44
43
)
45
44
return base , p , iniconfig ["pytest" ]
46
45
if (
@@ -99,7 +98,7 @@ def get_dir_from_path(path):
99
98
return [get_dir_from_path (path ) for path in possible_paths if path .exists ()]
100
99
101
100
102
- def determine_setup (inifile , args , rootdir_cmd_arg = None ):
101
+ def determine_setup (inifile , args , rootdir_cmd_arg = None , config = None ):
103
102
dirs = get_dirs_from_args (args )
104
103
if inifile :
105
104
iniconfig = py .iniconfig .IniConfig (inifile )
@@ -109,28 +108,30 @@ def determine_setup(inifile, args, rootdir_cmd_arg=None):
109
108
for section in sections :
110
109
try :
111
110
inicfg = iniconfig [section ]
112
- if is_cfg_file and section == "pytest" :
113
- from _pytest .warning_types import RemovedInPytest4Warning
111
+ if is_cfg_file and section == "pytest" and config is not None :
114
112
from _pytest .deprecated import CFG_PYTEST_SECTION
115
- import warnings
113
+ from _pytest .warning_types import RemovedInPytest4Warning
114
+ from _pytest .warnings import _issue_config_warning
116
115
117
- warnings .warn (
118
- CFG_PYTEST_SECTION .format (filename = str (inifile )),
119
- RemovedInPytest4Warning ,
116
+ _issue_config_warning (
117
+ RemovedInPytest4Warning (
118
+ CFG_PYTEST_SECTION .format (filename = str (inifile ))
119
+ ),
120
+ config ,
120
121
)
121
122
break
122
123
except KeyError :
123
124
inicfg = None
124
125
rootdir = get_common_ancestor (dirs )
125
126
else :
126
127
ancestor = get_common_ancestor (dirs )
127
- rootdir , inifile , inicfg = getcfg ([ancestor ])
128
+ rootdir , inifile , inicfg = getcfg ([ancestor ], config = config )
128
129
if rootdir is None :
129
130
for rootdir in ancestor .parts (reverse = True ):
130
131
if rootdir .join ("setup.py" ).exists ():
131
132
break
132
133
else :
133
- rootdir , inifile , inicfg = getcfg (dirs )
134
+ rootdir , inifile , inicfg = getcfg (dirs , config = config )
134
135
if rootdir is None :
135
136
rootdir = get_common_ancestor ([py .path .local (), ancestor ])
136
137
is_fs_root = os .path .splitdrive (str (rootdir ))[1 ] == "/"
0 commit comments