MCPcopy
hub / github.com/pytest-dev/pytest / _main

Function _main

src/_pytest/config/__init__.py:204–243  ·  view source on GitHub ↗
(
    *,
    args: list[str] | os.PathLike[str] | None = None,
    plugins: Sequence[str | _PluggyPlugin] | None = None,
    prog: str,
)

Source from the content-addressed store, hash-verified

202
203
204def _main(
205 *,
206 args: list[str] | os.PathLike[str] | None = None,
207 plugins: Sequence[str | _PluggyPlugin] | None = None,
208 prog: str,
209) -> int | ExitCode:
210 # Handle a single `--version`/`-V` argument early to avoid starting up the entire pytest infrastructure.
211 new_args = sys.argv[1:] if args is None else args
212 if (
213 isinstance(new_args, Sequence)
214 and (new_args.count("--version") + new_args.count("-V")) == 1
215 ):
216 sys.stdout.write(f"pytest {__version__}\n")
217 return ExitCode.OK
218
219 old_pytest_version = os.environ.get("PYTEST_VERSION")
220 try:
221 os.environ["PYTEST_VERSION"] = __version__
222 try:
223 config = _prepareconfig(new_args, plugins, prog=prog)
224 except ConftestImportFailure as e:
225 print_conftest_import_error(e, file=sys.stderr)
226 return ExitCode.USAGE_ERROR
227
228 try:
229 ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config)
230 try:
231 return ExitCode(ret)
232 except ValueError:
233 return ret
234 finally:
235 config._ensure_unconfigure()
236 except UsageError as e:
237 print_usage_error(e, file=sys.stderr)
238 return ExitCode.USAGE_ERROR
239 finally:
240 if old_pytest_version is None:
241 os.environ.pop("PYTEST_VERSION", None)
242 else:
243 os.environ["PYTEST_VERSION"] = old_pytest_version
244
245
246def _console_main() -> int:

Callers 2

mainFunction · 0.70
_console_mainFunction · 0.70

Calls 8

_prepareconfigFunction · 0.85
ExitCodeClass · 0.85
print_usage_errorFunction · 0.85
_ensure_unconfigureMethod · 0.80
popMethod · 0.80
writeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected