Skip to content

Commit e071568

Browse files
authored
Merge pull request #30 from dchiquito/fix-click-exception-ctx
Fix error when ctx is not defined on ClickExceptions
2 parents 73be8fb + a1e7f3c commit e071568

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

djclick/adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def run_from_argv(self, argv):
7171
if exit_code:
7272
sys.exit(exit_code)
7373
except click.ClickException as e:
74-
if getattr(e.ctx, "traceback", False): # NOCOV
74+
if getattr(e, "ctx", False) and getattr(e.ctx, "traceback", False): # NOCOV
7575
raise
7676
e.show()
7777
sys.exit(e.exit_code)

djclick/test/test_adapter.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@ def test_django_pythonpath(manage):
147147
) == b"1"
148148

149149

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

172169

170+
def test_click_exception(manage):
171+
with pytest.raises(subprocess.CalledProcessError) as e:
172+
manage("clickexceptioncmd")
173+
assert e.value.output == b"Error: Raised error description\n"
174+
assert e.value.returncode == 1
175+
176+
173177
def test_django_settings(manage):
174178
# The --settings switch only works from the command line (or if the django
175179
# settings where not setup before)... this means that we have to call it
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import djclick as click
2+
3+
4+
@click.command(version="20.0")
5+
def command():
6+
raise click.ClickException("Raised error description")

0 commit comments

Comments
 (0)