Skip to content
Myr

Merge pull request #363 from torfuspolymorphus/fix_362

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix issue #362.

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents 8056132, 807c5df · Browse files · 3 files+52 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+52 added−1 removed

  • tests:+43 added−0 removed
  • other:+9 added−1 removed

3 files+52 added−1 removed

modified:click/testing.py+7 added-1 removed
268 unmodified lines
269 exc_info = None270 with self.isolation(input=input, env=env, color=color) as out:271 exception = None272 exit_code = 0273 error_message = ''274275 try:276 cli.main(args=args or (),277 prog_name=self.get_default_prog_name(cli), **extra)278 except SystemExit as e:279 if e.code != 0:280 exception = e281 exit_code = e.code282 if not isinstance(exit_code, int):283 error_message = '%s\n' % exit_code284 exit_code = 1285 exc_info = sys.exc_info()286 except Exception as e:287 if not catch_exceptions:288 raise
1 unmodified line
290 exit_code = -1291 exc_info = sys.exc_info()292 finally:293 sys.stdout.flush()294 if not PY2:295 error_message = error_message.encode(self.charset)290 output = out.getvalue()296 output = out.getvalue() + error_message297298 return Result(runner=self,299 output_bytes=output,300 exit_code=exit_code,
19 unmodified lines
modified:tests/test_testing.py+43 added
1import sys23import pytest4import click56from click.testing import CliRunner
134 unmodified lines
141 runner = CliRunner()142 result = runner.invoke(cli, color=True)143 assert not result.exception144 assert result.output == ''145146147def test_exit_code_and_output_from_sys_exit():148 # See issue #362149 @click.command()150 def cli_string():151 click.echo('hello world')152 sys.exit('error')153154 @click.command()155 def cli_int():156 click.echo('hello world')157 sys.exit(1)158159 @click.command()160 def cli_float():161 click.echo('hello world')162 sys.exit(1.0)163164 @click.command()165 def cli_no_error():166 click.echo('hello world')167168 runner = CliRunner()169170 result = runner.invoke(cli_string)171 assert result.exit_code == 1172 assert result.output == 'hello world\nerror\n'173174 result = runner.invoke(cli_int)175 assert result.exit_code == 1176 assert result.output == 'hello world\n'177178 result = runner.invoke(cli_float)179 assert result.exit_code == 1180 assert result.output == 'hello world\n1.0\n'181182 result = runner.invoke(cli_no_error)183 assert result.exit_code == 0184 assert result.output == 'hello world\n'185
modified:CHANGES+2 added
10 unmodified lines
11- Removed various deprecated functionality.12- Atomic files now only accept the `w` mode.13- Change the usage part of help output for very long commands to wrap14 their arguments onto the next line, indented by 4 spaces.15- Fix a bug where return code and error messages were incorrect when16 using ``CliRunner``.1718Version 4.119-----------20
219 unmodified lines