Invokes a CLI command in an isolated environment. See :meth:`CliRunner.invoke <click.testing.CliRunner.invoke>` for full method documentation. See :ref:`testing-cli` for examples. If the ``obj`` argument is not given, passes an instance of :class:`~flask.cli.ScriptIn
( # type: ignore
self, cli: t.Any = None, args: t.Any = None, **kwargs: t.Any
)
| 273 | super().__init__(**kwargs) |
| 274 | |
| 275 | def invoke( # type: ignore |
| 276 | self, cli: t.Any = None, args: t.Any = None, **kwargs: t.Any |
| 277 | ) -> Result: |
| 278 | """Invokes a CLI command in an isolated environment. See |
| 279 | :meth:`CliRunner.invoke <click.testing.CliRunner.invoke>` for |
| 280 | full method documentation. See :ref:`testing-cli` for examples. |
| 281 | |
| 282 | If the ``obj`` argument is not given, passes an instance of |
| 283 | :class:`~flask.cli.ScriptInfo` that knows how to load the Flask |
| 284 | app being tested. |
| 285 | |
| 286 | :param cli: Command object to invoke. Default is the app's |
| 287 | :attr:`~flask.app.Flask.cli` group. |
| 288 | :param args: List of strings to invoke the command with. |
| 289 | |
| 290 | :return: a :class:`~click.testing.Result` object. |
| 291 | """ |
| 292 | if cli is None: |
| 293 | cli = self.app.cli |
| 294 | |
| 295 | if "obj" not in kwargs: |
| 296 | kwargs["obj"] = ScriptInfo(create_app=lambda: self.app) |
| 297 | |
| 298 | return super().invoke(cli, args, **kwargs) |