Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion djclick/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def run_from_argv(self, argv):
if exit_code:
sys.exit(exit_code)
except click.ClickException as e:
if getattr(e.ctx, "traceback", False): # NOCOV
if getattr(e, "ctx", False) and getattr(e.ctx, "traceback", False): # NOCOV
raise
e.show()
sys.exit(e.exit_code)
Expand Down
10 changes: 7 additions & 3 deletions djclick/test/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ def test_django_pythonpath(manage):
) == b"1"


@pytest.mark.xfail(
reason="Looks like CommandError no longer " "results in non-zero exit status"
)
def test_django_traceback(manage):
with pytest.raises(subprocess.CalledProcessError) as e:
manage("errcmd")
Expand All @@ -170,6 +167,13 @@ def test_django_traceback(manage):
assert e.returncode == 1


def test_click_exception(manage):
with pytest.raises(subprocess.CalledProcessError) as e:
manage("clickexceptioncmd")
assert e.value.output == b"Error: Raised error description\n"
assert e.value.returncode == 1


def test_django_settings(manage):
# The --settings switch only works from the command line (or if the django
# settings where not setup before)... this means that we have to call it
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import djclick as click


@click.command(version="20.0")
def command():
raise click.ClickException("Raised error description")