-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
click.testing.CliRunner.invoke prevents use of pdb #843
Comments
@rsyring Perhaps you've figured this out in the interim, but the workaround that I've come up for this is to mock out For example:
Please let me know if you have any more questions. |
Since You can try this workaround: import sys
import pdb
import click
from click.testing import CliRunner
stdin, stdout = sys.stdin, sys.stdout
def set_trace():
pdb.Pdb(stdin=stdin, stdout=stdout).set_trace()
@click.command()
def main():
set_trace()
if __name__ == '__main__':
runner = CliRunner()
print(runner.invoke(main)) How click should be handling this issue is left open for discussion. |
This might be useful for some: Click CliRunner with PDB working better under pytest |
I use this snipped and it works basically always (argsparse, click, sys.argv): import unittest
import pytest
from thing.__main__ import cli
class TestCli(unittest.TestCase):
@pytest.fixture(autouse=True)
def capsys(self, capsys):
self.capsys = capsys
def test_cli(self):
with pytest.raises(SystemExit) as ex:
cli(["create", "--name", "test"])
self.assertEqual(ex.value.code, 0)
out, err = self.capsys.readouterr()
self.assertEqual(out, "Succesfully created test\n") |
I tried out a few samples and workarounds from here. The I went through In my opinion, it will be better to leave this as it is until there is a better way to mock |
I had the same error, calling PDB from pytest using |
Will someone please re-open #138. It's still a problem with Click 6.7. In particular, my stack trace ends with:
And there is explanation about why this is happening in the related issue.
The text was updated successfully, but these errors were encountered: