You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
click.testing.CliRunner.invoke prevents use of pdb #138
Here's another one (related to #136). I wanted to explore the contents of the context object passed to a command decorated with @click.pass_context.
But when I try dropping a pdb.set_trace into the invoked command, it immediately quits...but only when invoked via the CliRunner.
if I actually invoke the command from the command line, the debugger works as expected.
Maybe something to do with the handling of stdin and stdout by CliRunner.invoke?
Here's an example:
"""(click)(master ? =)[~/projects/click]$ python click_bdb_swallow.py F======================================================================FAIL: test_noarguments (__main__.FooTests)----------------------------------------------------------------------Traceback (most recent call last): File "click_bdb_swallow.py", line 21, in test_noarguments result = runner.invoke(foo)AssertionError: <object object at 0x7fb7d0f9f1b0> != <Result BdbQuit()>----------------------------------------------------------------------Ran 1 test in 0.006sFAILED (failures=1)"""importunittestimportclickfromclick.testingimportCliRunner@click.command()@click.pass_contextdeffoo(context):
""" I want to drop to pdb in here so that I can explore the context object, but pdb just exits, maybe because of the way CliRunner.invoke changes stdin, stdout. """importpdb; pdb.set_trace()
classFooTests(unittest.TestCase):
deftest_noarguments(self):
runner=CliRunner()
result=runner.invoke(foo)
# And again it's confusing that BdbQuit has been swallowed by invoke# (see https://github.com/mitsuhiko/click/issues/136)self.assertEqual(object(), result)
if__name__=='__main__':
unittest.main()
Reacted by Paul Garner, Silvio Tomatis and Denis Rykov
@mitsuhiko, could you explain how to prevent pdb from quiting when started under CliRunner.invoke ?
I have tried to provide the input argument to invoke(), and that seems to let me pass input to a running pdb, however, the output seems to get eaten by invoke().
Looking at the code, it's not clear to me how to avoid this effect when using invoke().
I'm on click 3.3.
Could this be happening due to CliRunner.isolation() replacing sys.stdin with a StringIO(), which is empty by default. pdb then reads the empty buffer and gets a EOF ?
Reacted by Nick Zaccardi, Gaurav Butola, Paul Garner and Silvio Tomatis
Click can provide lightweight method that just calls cli.main and catches SystemExit. I'm not sure why catch_exceptions is True by default. From my perspective it's better to get failed test and see default traceback.
Activity
mitsuhiko commentedon Jun 14, 2014
There is a way to prevent this with Click 3.0
torbjorntorbjorn commentedon Feb 17, 2015
@mitsuhiko, could you explain how to prevent pdb from quiting when started under CliRunner.invoke ?
I have tried to provide the input argument to invoke(), and that seems to let me pass input to a running pdb, however, the output seems to get eaten by invoke().
Looking at the code, it's not clear to me how to avoid this effect when using invoke().
I'm on click 3.3.
nikhilkalige commentedon Feb 23, 2015
call
invokewithcatch_exceptions=Falsetorbjorntorbjorn commentedon Feb 24, 2015
It seems like calling with
catch_exceptions=Falsemakes invoke() raise a bdb.BdbQuit exception.Here is a gist which trigger the behaviors I'm seeing. I'm on Python 2.7.3 on Debian stable.
https://gist.github.com/anonymous/1f1ea59bac42e8ea6b2b
Could this be happening due to CliRunner.isolation() replacing sys.stdin with a StringIO(), which is empty by default. pdb then reads the empty buffer and gets a EOF ?
DXist commentedon Jun 3, 2016
+1
Clickcan provide lightweight method that just callscli.mainand catchesSystemExit. I'm not sure whycatch_exceptionsis True by default. From my perspective it's better to get failed test and see default traceback.endzyme commentedon Mar 23, 2017
getting this in Click 6.6 - anyone ever find a workaround? When setting
catch_exceptions=Falsei still get dumped inbresmith-wayfair commentedon May 19, 2017
also getting this on click==6.6
would love to get a solution to this, making it really hard to debug this issue i'm having
juledwar commentedon May 24, 2017
I am using rpdb until this is fixed. Not ideal but serves a need.
Elfoniok commentedon Aug 7, 2017
Hey
Name: click
Version: 6.7
Still having this issue. This occurs on python 3.5.3 i didn't observe this on python 2.7.
chaoflow commentedon Oct 25, 2017
as well with b471d34 and python 3.5.2
jtcho commentedon May 16, 2018
I have provided a workaround that worked for me in #843.