Skip to content

Commit 478a244

Browse files
authored
main: args must be a list, not tuple (#6791)
Passing in a tuple crashes in `_prepareconfig`: def test_invoke_with_tuple(self): > pytest.main(("-h",)) src/_pytest/config/__init__.py:82: in main config = _prepareconfig(args, plugins) src/_pytest/config/__init__.py:229: in _prepareconfig return pluginmanager.hook.pytest_cmdline_parse( … src/_pytest/helpconfig.py:98: in pytest_cmdline_parse config = outcome.get_result() # type: Config src/_pytest/config/__init__.py:808: in pytest_cmdline_parse self.parse(args) src/_pytest/config/__init__.py:1017: in parse self._preparse(args, addopts=addopts) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _preparse(self, args: List[str], addopts: bool = True) -> None: … if addopts: ini_addopts = self.getini("addopts") if ini_addopts: > args[:] = self._validate_args(ini_addopts, "via addopts config") + args E TypeError: can only concatenate list (not "tuple") to list addopts = True args = ('-h',) env_addopts = '' ini_addopts = ['-rfEX', …] src/_pytest/config/__init__.py:956: TypeError: can only concatenate list (not "tuple") to list Might be worth handling (converting it to a list for example), but it was documented to be a list to begin with when removing support for strings (a7e4016).
1 parent 7c0d1ca commit 478a244

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/_pytest/config/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,15 @@ def get_plugin_manager():
233233
return get_config().pluginmanager
234234

235235

236-
def _prepareconfig(args=None, plugins=None):
236+
def _prepareconfig(
237+
args: Optional[Union[py.path.local, List[str]]] = None, plugins=None
238+
):
237239
if args is None:
238240
args = sys.argv[1:]
239241
elif isinstance(args, py.path.local):
240242
args = [str(args)]
241-
elif not isinstance(args, (tuple, list)):
242-
msg = "`args` parameter expected to be a list or tuple of strings, got: {!r} (type: {})"
243+
elif not isinstance(args, list):
244+
msg = "`args` parameter expected to be a list of strings, got: {!r} (type: {})"
243245
raise TypeError(msg.format(args, type(args)))
244246

245247
config = get_config(args, plugins)

testing/acceptance_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def test_equivalence_pytest_pytest(self):
606606

607607
def test_invoke_with_invalid_type(self):
608608
with pytest.raises(
609-
TypeError, match="expected to be a list or tuple of strings, got: '-h'"
609+
TypeError, match="expected to be a list of strings, got: '-h'"
610610
):
611611
pytest.main("-h")
612612

0 commit comments

Comments
 (0)