Merge pull request #6023 from blueyed/main-exitcode

pytest.main: return ExitCode
This commit is contained in:
Daniel Hahler 2019-10-23 07:48:17 +02:00 committed by GitHub
commit c71a2c9f80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -0,0 +1 @@
``pytest.main`` returns a ``pytest.ExitCode`` instance now, except for when custom exit codes are used (where it returns ``int`` then still).

View File

@ -18,6 +18,7 @@ from typing import Optional
from typing import Sequence from typing import Sequence
from typing import Set from typing import Set
from typing import Tuple from typing import Tuple
from typing import Union
import attr import attr
import py import py
@ -56,7 +57,7 @@ class ConftestImportFailure(Exception):
self.excinfo = excinfo # type: Tuple[Type[Exception], Exception, TracebackType] self.excinfo = excinfo # type: Tuple[Type[Exception], Exception, TracebackType]
def main(args=None, plugins=None): def main(args=None, plugins=None) -> "Union[int, _pytest.main.ExitCode]":
""" return exit code, after performing an in-process test run. """ return exit code, after performing an in-process test run.
:arg args: list of command line arguments. :arg args: list of command line arguments.
@ -84,10 +85,16 @@ def main(args=None, plugins=None):
formatted_tb = str(exc_repr) formatted_tb = str(exc_repr)
for line in formatted_tb.splitlines(): for line in formatted_tb.splitlines():
tw.line(line.rstrip(), red=True) tw.line(line.rstrip(), red=True)
return 4 return ExitCode.USAGE_ERROR
else: else:
try: try:
return config.hook.pytest_cmdline_main(config=config) ret = config.hook.pytest_cmdline_main(
config=config
) # type: Union[ExitCode, int]
try:
return ExitCode(ret)
except ValueError:
return ret
finally: finally:
config._ensure_unconfigure() config._ensure_unconfigure()
except UsageError as e: except UsageError as e: