File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -202,6 +202,9 @@ time or change existing behaviors in order to make them less surprising/more use
202
202
removed in pytest-4.0 (`#1684 `_).
203
203
Thanks `@nicoddemus `_ for the PR.
204
204
205
+ * Passing a command-line string to ``pytest.main() `` is considered deprecated and scheduled
206
+ for removal in pytest-4.0. It is recommended to pass a list of arguments instead (`#1723 `_).
207
+
205
208
* Rename ``getfuncargvalue `` to ``getfixturevalue ``. ``getfuncargvalue `` is
206
209
still present but is now considered deprecated. Thanks to `@RedBeardCode `_ and `@tomviner `_
207
210
for the PR (`#1626 `_).
@@ -279,6 +282,7 @@ time or change existing behaviors in order to make them less surprising/more use
279
282
.. _#1633 : https://github.com/pytest-dev/pytest/pull/1633
280
283
.. _#1664 : https://github.com/pytest-dev/pytest/pull/1664
281
284
.. _#1684 : https://github.com/pytest-dev/pytest/pull/1684
285
+ .. _#1723 : https://github.com/pytest-dev/pytest/pull/1723
282
286
283
287
.. _@DRMacIver : https://github.com/DRMacIver
284
288
.. _@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