Merge pull request #6023 from blueyed/main-exitcode
pytest.main: return ExitCode
This commit is contained in:
commit
c71a2c9f80
|
@ -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).
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue