Skip to content

Fix congratulations message that occurs on KeyboardInterrupt during package installation #1725

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

Merged
merged 1 commit into from
Oct 30, 2020
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
1 change: 1 addition & 0 deletions docs/changelog/1453.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the false ``congratulations`` message that appears when a ``KeyboardInterrupt`` occurs during package installation. - by :user:`gnikonorov`
6 changes: 6 additions & 0 deletions src/tox/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ def expand(val):
redirect=reporter.verbosity() < reporter.Verbosity.DEBUG,
env=env,
)
except KeyboardInterrupt:
self.status = "keyboardinterrupt"
raise
finally:
sys.stdout = old_stdout

Expand Down Expand Up @@ -636,6 +639,9 @@ def setupenv(self):
status = e
if self.envconfig.config.option.skip_missing_interpreters == "true":
default_ret_code = 0
except KeyboardInterrupt:
self.status = "keyboardinterrupt"
raise
if status:
str_status = str(status)
command_log = envlog.get_commandlog("setup")
Expand Down
20 changes: 18 additions & 2 deletions tests/unit/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,18 @@ def test_create(mocksession, newconfig):
assert venv.path_config.check(exists=False)


def test_create_KeyboardInterrupt(mocksession, newconfig, mocker):
@pytest.mark.parametrize("patched_venv_methodname", ["_pcall", "update"])
def test_create_KeyboardInterrupt(mocksession, newconfig, mocker, patched_venv_methodname):
config = newconfig(
[],
"""\
[testenv:py123]
deps = pip >= 19.3.1
""",
)
mocksession.new_config(config)
venv = mocksession.getvenv("py123")
mocker.patch.object(venv, "_pcall", side_effect=KeyboardInterrupt)
mocker.patch.object(venv, patched_venv_methodname, side_effect=KeyboardInterrupt)
with pytest.raises(KeyboardInterrupt):
venv.setupenv()

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


def test_run_install_command_handles_KeyboardInterrupt(newmocksession, mocker):
mocksession = newmocksession([], "")
venv = mocksession.getvenv("python")
venv.just_created = True
venv.envconfig.envdir.ensure(dir=1)

mocker.patch.object(venv, "_pcall", side_effect=KeyboardInterrupt)
with mocksession.newaction(venv.name, "hello") as action:
with pytest.raises(KeyboardInterrupt):
venv.run_install_command(packages=["whatever"], action=action)

assert venv.status == "keyboardinterrupt"


def test_command_relative_issue36(newmocksession, tmpdir, monkeypatch):
mocksession = newmocksession(
[],
Expand Down