Skip to content

Commit

Permalink
fix exit_code for click.testing.CliRunner.invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
timfeirg committed Feb 25, 2017
1 parent 8d9dd46 commit a01500b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,5 @@ build
docs/_build
click.egg-info
.tox
.cache
.ropeproject
20 changes: 12 additions & 8 deletions click/testing.py
@@ -1,9 +1,9 @@
import contextlib
import os
import sys
import shlex
import shutil
import sys
import tempfile
import contextlib
import shlex

from ._compat import iteritems, PY2, string_types

Expand Down Expand Up @@ -197,6 +197,7 @@ def _getchar(echo):
return char

default_color = color

def should_strip_ansi(stream=None, color=None):
if color is None:
return not default_color
Expand Down Expand Up @@ -285,21 +286,24 @@ def invoke(self, cli, args=None, input=None, env=None,
cli.main(args=args or (),
prog_name=self.get_default_prog_name(cli), **extra)
except SystemExit as e:
if e.code != 0:
exception = e

exc_info = sys.exc_info()

exit_code = e.code
if exit_code is None:
exit_code = 0

if exit_code != 0:
exception = e

if not isinstance(exit_code, int):
sys.stdout.write(str(exit_code))
sys.stdout.write('\n')
exit_code = 1

except Exception as e:
if not catch_exceptions:
raise
exception = e
exit_code = -1
exit_code = 1
exc_info = sys.exc_info()
finally:
sys.stdout.flush()
Expand Down

0 comments on commit a01500b

Please sign in to comment.