Improved failed test output

This commit is contained in:
Jakub Roztocil 2016-03-02 13:16:41 +08:00
parent 564670566c
commit 66e168b2af
4 changed files with 24 additions and 8 deletions

View File

@ -12,12 +12,12 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
* Added ``Content-Type`` of files uploaded in ``multipart/form-data`` requests * Added ``Content-Type`` of files uploaded in ``multipart/form-data`` requests
* Added ``--ssl=<PROTOCOL>`` to specify the desired SSL/TLS protocol version * Added ``--ssl=<PROTOCOL>`` to specify the desired SSL/TLS protocol version
to use for HTTPS requests. to use for HTTPS requests.
* Added JSON detection with ``--json, -j`` to work around incorrect
``Content-Type``
* Added ``--show-redirects, -R`` to show intermediate responses with ``--follow`` * Added ``--show-redirects, -R`` to show intermediate responses with ``--follow``
* Added ``--max-redirects`` (default 30) * Added ``--max-redirects`` (default 30)
* Added ``-A`` as short name for ``--auth-type`` * Added ``-A`` as short name for ``--auth-type``
* Added ``-F`` as short name for ``--follow`` * Added ``-F`` as short name for ``--follow``
* Added JSON detection with ``--json, -j`` to work around incorrect
``Content-Type``
* Redirected ``stdout`` doesn't trigger an error anymore when ``--output FILE`` * Redirected ``stdout`` doesn't trigger an error anymore when ``--output FILE``
is set. is set.
* Changed the default ``--style`` back to ``solarized`` for better support * Changed the default ``--style`` back to ``solarized`` for better support

View File

@ -18,3 +18,10 @@ class ExitStatus:
ERROR_HTTP_3XX = 3 ERROR_HTTP_3XX = 3
ERROR_HTTP_4XX = 4 ERROR_HTTP_4XX = 4
ERROR_HTTP_5XX = 5 ERROR_HTTP_5XX = 5
EXIT_STATUS_LABELS = dict(
(value, key)
for key, value in ExitStatus.__dict__.items()
if key.isupper()
)

View File

@ -1,3 +1,2 @@
[pytest] [pytest]
addopts = --tb=native
norecursedirs = tests/fixtures norecursedirs = tests/fixtures

View File

@ -6,7 +6,7 @@ import time
import json import json
import tempfile import tempfile
import httpie from httpie import ExitStatus, EXIT_STATUS_LABELS
from httpie.context import Environment from httpie.context import Environment
from httpie.core import main from httpie.core import main
from httpie.compat import bytes, str from httpie.compat import bytes, str
@ -135,6 +135,10 @@ class StrCLIResponse(str, BaseCLIResponse):
return self._json return self._json
class ExitStatusException(Exception):
pass
def http(*args, **kwargs): def http(*args, **kwargs):
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
""" """
@ -205,7 +209,7 @@ def http(*args, **kwargs):
time.sleep(.5) time.sleep(.5)
except SystemExit: except SystemExit:
if error_exit_ok: if error_exit_ok:
exit_status = httpie.ExitStatus.ERROR exit_status = ExitStatus.ERROR
else: else:
dump_stderr() dump_stderr()
raise raise
@ -214,9 +218,15 @@ def http(*args, **kwargs):
sys.stderr.write(stderr.read()) sys.stderr.write(stderr.read())
raise raise
else: else:
if exit_status != httpie.ExitStatus.OK and not error_exit_ok: if not error_exit_ok and exit_status != ExitStatus.OK:
dump_stderr() dump_stderr()
raise Exception('Unexpected exit status: %s', exit_status) raise ExitStatusException(
'httpie.core.main() unexpectedly returned'
' a non-zero exit status: {0} ({1})'.format(
exit_status,
EXIT_STATUS_LABELS[exit_status]
)
)
stdout.seek(0) stdout.seek(0)
stderr.seek(0) stderr.seek(0)
@ -232,7 +242,7 @@ def http(*args, **kwargs):
r.stderr = stderr.read() r.stderr = stderr.read()
r.exit_status = exit_status r.exit_status = exit_status
if r.exit_status != httpie.ExitStatus.OK: if r.exit_status != ExitStatus.OK:
sys.stderr.write(r.stderr) sys.stderr.write(r.stderr)
return r return r