File tree 3 files changed +25
-0
lines changed 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -203,6 +203,9 @@ time or change existing behaviors in order to make them less surprising/more use
203
203
removed in pytest-4.0 (`#1684 `_).
204
204
Thanks `@nicoddemus `_ for the PR.
205
205
206
+ * Passing a command-line string to ``pytest.main() `` is considered deprecated and scheduled
207
+ for removal in pytest-4.0. It is recommended to pass a list of arguments instead (`#1723 `_).
208
+
206
209
* Rename ``getfuncargvalue `` to ``getfixturevalue ``. ``getfuncargvalue `` is
207
210
still present but is now considered deprecated. Thanks to `@RedBeardCode `_ and `@tomviner `_
208
211
for the PR (`#1626 `_).
@@ -282,6 +285,7 @@ time or change existing behaviors in order to make them less surprising/more use
282
285
.. _#1633 : https://github.com/pytest-dev/pytest/pull/1633
283
286
.. _#1664 : https://github.com/pytest-dev/pytest/pull/1664
284
287
.. _#1684 : https://github.com/pytest-dev/pytest/pull/1684
288
+ .. _#1723 : https://github.com/pytest-dev/pytest/pull/1723
285
289
286
290
.. _@DRMacIver : https://github.com/DRMacIver
287
291
.. _@RedBeardCode : https://github.com/RedBeardCode
Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ def get_plugin_manager():
98
98
return get_config ().pluginmanager
99
99
100
100
def _prepareconfig (args = None , plugins = None ):
101
+ warning = None
101
102
if args is None :
102
103
args = sys .argv [1 :]
103
104
elif isinstance (args , py .path .local ):
@@ -106,6 +107,10 @@ def _prepareconfig(args=None, plugins=None):
106
107
if not isinstance (args , str ):
107
108
raise ValueError ("not a string or argument list: %r" % (args ,))
108
109
args = shlex .split (args , posix = sys .platform != "win32" )
110
+ # we want to remove this way of passing arguments to pytest.main()
111
+ # in pytest-4.0
112
+ warning = 'passing a string to pytest.main() is deprecated, ' \
113
+ 'pass a list of arguments instead.'
109
114
config = get_config ()
110
115
pluginmanager = config .pluginmanager
111
116
try :
@@ -115,6 +120,8 @@ def _prepareconfig(args=None, plugins=None):
115
120
pluginmanager .consider_pluginarg (plugin )
116
121
else :
117
122
pluginmanager .register (plugin )
123
+ if warning :
124
+ config .warn ('C1' , warning )
118
125
return pluginmanager .hook .pytest_cmdline_parse (
119
126
pluginmanager = pluginmanager , args = args )
120
127
except BaseException :
Original file line number Diff line number Diff line change @@ -795,3 +795,17 @@ def test_funcarg_prefix(value):
795
795
'Please remove the prefix and use the @pytest.fixture decorator instead.' ),
796
796
'*1 passed*' ,
797
797
])
798
+
799
+
800
+ def test_str_args_deprecated (tmpdir , testdir ):
801
+ """Deprecate passing strings to pytest.main(). Scheduled for removal in pytest-4.0."""
802
+ warnings = []
803
+
804
+ class Collect :
805
+ def pytest_logwarning (self , message ):
806
+ warnings .append (message )
807
+
808
+ ret = pytest .main ("%s -x" % tmpdir , plugins = [Collect ()])
809
+ testdir .delete_loaded_modules ()
810
+ assert warnings == ['passing a string to pytest.main() is deprecated, pass a list of arguments instead.' ]
811
+ assert ret == EXIT_NOTESTSCOLLECTED
You can’t perform that action at this time.
0 commit comments