Skip to content

Commit 7df5b9a

Browse files
authored
Fix congratulations message that occurs on KeyboardInterrupt during package installation (#1725)
1 parent 470ad94 commit 7df5b9a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

docs/changelog/1453.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the false ``congratulations`` message that appears when a ``KeyboardInterrupt`` occurs during package installation. - by :user:`gnikonorov`

src/tox/venv.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ def expand(val):
430430
redirect=reporter.verbosity() < reporter.Verbosity.DEBUG,
431431
env=env,
432432
)
433+
except KeyboardInterrupt:
434+
self.status = "keyboardinterrupt"
435+
raise
433436
finally:
434437
sys.stdout = old_stdout
435438

@@ -636,6 +639,9 @@ def setupenv(self):
636639
status = e
637640
if self.envconfig.config.option.skip_missing_interpreters == "true":
638641
default_ret_code = 0
642+
except KeyboardInterrupt:
643+
self.status = "keyboardinterrupt"
644+
raise
639645
if status:
640646
str_status = str(status)
641647
command_log = envlog.get_commandlog("setup")

tests/unit/test_venv.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,18 @@ def test_create(mocksession, newconfig):
8484
assert venv.path_config.check(exists=False)
8585

8686

87-
def test_create_KeyboardInterrupt(mocksession, newconfig, mocker):
87+
@pytest.mark.parametrize("patched_venv_methodname", ["_pcall", "update"])
88+
def test_create_KeyboardInterrupt(mocksession, newconfig, mocker, patched_venv_methodname):
8889
config = newconfig(
8990
[],
9091
"""\
9192
[testenv:py123]
93+
deps = pip >= 19.3.1
9294
""",
9395
)
9496
mocksession.new_config(config)
9597
venv = mocksession.getvenv("py123")
96-
mocker.patch.object(venv, "_pcall", side_effect=KeyboardInterrupt)
98+
mocker.patch.object(venv, patched_venv_methodname, side_effect=KeyboardInterrupt)
9799
with pytest.raises(KeyboardInterrupt):
98100
venv.setupenv()
99101

@@ -916,6 +918,20 @@ def test_run_custom_install_command(newmocksession):
916918
assert pcalls[0].args[1:] == ["whatever"]
917919

918920

921+
def test_run_install_command_handles_KeyboardInterrupt(newmocksession, mocker):
922+
mocksession = newmocksession([], "")
923+
venv = mocksession.getvenv("python")
924+
venv.just_created = True
925+
venv.envconfig.envdir.ensure(dir=1)
926+
927+
mocker.patch.object(venv, "_pcall", side_effect=KeyboardInterrupt)
928+
with mocksession.newaction(venv.name, "hello") as action:
929+
with pytest.raises(KeyboardInterrupt):
930+
venv.run_install_command(packages=["whatever"], action=action)
931+
932+
assert venv.status == "keyboardinterrupt"
933+
934+
919935
def test_command_relative_issue36(newmocksession, tmpdir, monkeypatch):
920936
mocksession = newmocksession(
921937
[],

0 commit comments

Comments
 (0)