summaryrefslogtreecommitdiff
path: root/tests/test_testing.py
diff options
context:
space:
mode:
authorTorf <mail@torf.cc>2015-06-19 19:56:24 +0200
committerTorf <mail@torf.cc>2015-06-20 18:20:18 +0200
commit807c5df0b9528d387ff48f0e593907760b2ad6ce (patch)
tree83f5a3e3ed5793dd52f19d37859f4030c5f23f11 /tests/test_testing.py
parent8056132bfe09d59eb7f4cb199a87e63ec634d052 (diff)
downloadclick-807c5df0b9528d387ff48f0e593907760b2ad6ce.tar.gz
Fixed issue #362.
Diffstat (limited to 'tests/test_testing.py')
-rw-r--r--tests/test_testing.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_testing.py b/tests/test_testing.py
index 590248d..5aabaa3 100644
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -1,3 +1,5 @@
+import sys
+
import pytest
import click
@@ -140,3 +142,44 @@ def test_with_color_but_pause_not_blocking():
result = runner.invoke(cli, color=True)
assert not result.exception
assert result.output == ''
+
+
+def test_exit_code_and_output_from_sys_exit():
+ # See issue #362
+ @click.command()
+ def cli_string():
+ click.echo('hello world')
+ sys.exit('error')
+
+ @click.command()
+ def cli_int():
+ click.echo('hello world')
+ sys.exit(1)
+
+ @click.command()
+ def cli_float():
+ click.echo('hello world')
+ sys.exit(1.0)
+
+ @click.command()
+ def cli_no_error():
+ click.echo('hello world')
+
+ runner = CliRunner()
+
+ result = runner.invoke(cli_string)
+ assert result.exit_code == 1
+ assert result.output == 'hello world\nerror\n'
+
+ result = runner.invoke(cli_int)
+ assert result.exit_code == 1
+ assert result.output == 'hello world\n'
+
+ result = runner.invoke(cli_float)
+ assert result.exit_code == 1
+ assert result.output == 'hello world\n1.0\n'
+
+ result = runner.invoke(cli_no_error)
+ assert result.exit_code == 0
+ assert result.output == 'hello world\n'
+