Perform an in-process test run. :param args: List of command line arguments. :param plugins: List of plugin objects to be auto-registered during initialization. :returns: An exit code.
(
args: Optional[Union[List[str], "os.PathLike[str]"]] = None,
plugins: Optional[Sequence[Union[str, _PluggyPlugin]]] = None,
)
| 131 | |
| 132 | |
| 133 | def main( |
| 134 | args: Optional[Union[List[str], "os.PathLike[str]"]] = None, |
| 135 | plugins: Optional[Sequence[Union[str, _PluggyPlugin]]] = None, |
| 136 | ) -> Union[int, ExitCode]: |
| 137 | """Perform an in-process test run. |
| 138 | |
| 139 | :param args: List of command line arguments. |
| 140 | :param plugins: List of plugin objects to be auto-registered during initialization. |
| 141 | |
| 142 | :returns: An exit code. |
| 143 | """ |
| 144 | try: |
| 145 | try: |
| 146 | config = _prepareconfig(args, plugins) |
| 147 | except ConftestImportFailure as e: |
| 148 | exc_info = ExceptionInfo.from_exc_info(e.excinfo) |
| 149 | tw = TerminalWriter(sys.stderr) |
| 150 | tw.line(f"ImportError while loading conftest '{e.path}'.", red=True) |
| 151 | exc_info.traceback = exc_info.traceback.filter( |
| 152 | filter_traceback_for_conftest_import_failure |
| 153 | ) |
| 154 | exc_repr = ( |
| 155 | exc_info.getrepr(style="short", chain=False) |
| 156 | if exc_info.traceback |
| 157 | else exc_info.exconly() |
| 158 | ) |
| 159 | formatted_tb = str(exc_repr) |
| 160 | for line in formatted_tb.splitlines(): |
| 161 | tw.line(line.rstrip(), red=True) |
| 162 | return ExitCode.USAGE_ERROR |
| 163 | else: |
| 164 | try: |
| 165 | ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main( |
| 166 | config=config |
| 167 | ) |
| 168 | try: |
| 169 | return ExitCode(ret) |
| 170 | except ValueError: |
| 171 | return ret |
| 172 | finally: |
| 173 | config._ensure_unconfigure() |
| 174 | except UsageError as e: |
| 175 | tw = TerminalWriter(sys.stderr) |
| 176 | for msg in e.args: |
| 177 | tw.line(f"ERROR: {msg}\n", red=True) |
| 178 | return ExitCode.USAGE_ERROR |
| 179 | |
| 180 | |
| 181 | def console_main() -> int: |