Add new "pytest_modify_args" hook
This commit is contained in:
parent
fab696dcd1
commit
25b88e542b
1
AUTHORS
1
AUTHORS
|
@ -98,6 +98,7 @@ David Szotten
|
||||||
David Vierra
|
David Vierra
|
||||||
Daw-Ran Liou
|
Daw-Ran Liou
|
||||||
Debi Mishra
|
Debi Mishra
|
||||||
|
Delgan
|
||||||
Denis Kirisov
|
Denis Kirisov
|
||||||
Denivy Braiam Rück
|
Denivy Braiam Rück
|
||||||
Dhiren Serai
|
Dhiren Serai
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Added a new ``pytest_modify_args`` hook.
|
|
@ -627,6 +627,8 @@ Initialization hooks
|
||||||
|
|
||||||
Initialization hooks called for plugins and ``conftest.py`` files.
|
Initialization hooks called for plugins and ``conftest.py`` files.
|
||||||
|
|
||||||
|
.. hook:: pytest_modify_args
|
||||||
|
.. autofunction:: pytest_modify_args
|
||||||
.. hook:: pytest_addoption
|
.. hook:: pytest_addoption
|
||||||
.. autofunction:: pytest_addoption
|
.. autofunction:: pytest_addoption
|
||||||
.. hook:: pytest_addhooks
|
.. hook:: pytest_addhooks
|
||||||
|
|
|
@ -1318,6 +1318,7 @@ class Config:
|
||||||
kwargs=dict(pluginmanager=self.pluginmanager)
|
kwargs=dict(pluginmanager=self.pluginmanager)
|
||||||
)
|
)
|
||||||
self._preparse(args, addopts=addopts)
|
self._preparse(args, addopts=addopts)
|
||||||
|
self.hook.pytest_modify_args(args=args)
|
||||||
# XXX deprecated hook:
|
# XXX deprecated hook:
|
||||||
self.hook.pytest_cmdline_preparse(config=self, args=args)
|
self.hook.pytest_cmdline_preparse(config=self, args=args)
|
||||||
self._parser.after_preparse = True # type: ignore
|
self._parser.after_preparse = True # type: ignore
|
||||||
|
|
|
@ -172,6 +172,13 @@ def pytest_cmdline_preparse(config: "Config", args: List[str]) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_modify_args(args: List[str]) -> None:
|
||||||
|
"""Modify command line arguments before option parsing.
|
||||||
|
|
||||||
|
:param List[str] args: Arguments passed on the command line.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
@hookspec(firstresult=True)
|
@hookspec(firstresult=True)
|
||||||
def pytest_cmdline_main(config: "Config") -> Optional[Union["ExitCode", int]]:
|
def pytest_cmdline_main(config: "Config") -> Optional[Union["ExitCode", int]]:
|
||||||
"""Called for performing the main command line action. The default
|
"""Called for performing the main command line action. The default
|
||||||
|
|
|
@ -1296,6 +1296,17 @@ def test_load_initial_conftest_last_ordering(_config_for_test):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_modify_args_hook(pytester: Pytester) -> None:
|
||||||
|
pytester.makeconftest(
|
||||||
|
"""
|
||||||
|
def pytest_modify_args(args):
|
||||||
|
args.append("-h")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = pytester.runpytest()
|
||||||
|
result.stdout.fnmatch_lines(["*pytest*", "*-h*"])
|
||||||
|
|
||||||
|
|
||||||
def test_get_plugin_specs_as_list() -> None:
|
def test_get_plugin_specs_as_list() -> None:
|
||||||
def exp_match(val: object) -> str:
|
def exp_match(val: object) -> str:
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue