mirror of
https://github.com/enpaul/tox-poetry-installer.git
synced 2025-01-15 08:43:29 +00:00
Merge pull request #87 from chriskuehl/raise-exceptions-from-install
Ensure exceptions which occur during install are propagated
This commit is contained in:
commit
c6c35636cd
@ -1,6 +1,8 @@
|
|||||||
# pylint: disable=missing-module-docstring, redefined-outer-name, unused-argument, wrong-import-order, unused-import
|
# pylint: disable=missing-module-docstring, redefined-outer-name, unused-argument, wrong-import-order, unused-import
|
||||||
import time
|
import time
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
import pytest
|
||||||
import tox.venv
|
import tox.venv
|
||||||
from poetry.factory import Factory
|
from poetry.factory import Factory
|
||||||
|
|
||||||
@ -57,3 +59,32 @@ def test_parallelization(mock_venv, mock_poetry_factory):
|
|||||||
assert round(parallel * 5) == round(sequential)
|
assert round(parallel * 5) == round(sequential)
|
||||||
assert round(sequential) == len(set(to_install))
|
assert round(sequential) == len(set(to_install))
|
||||||
assert round(parallel * 5) == len(set(to_install))
|
assert round(parallel * 5) == len(set(to_install))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("num_threads", (0, 8))
|
||||||
|
def test_propagates_exceptions_during_installation(
|
||||||
|
mock_venv, mock_poetry_factory, num_threads
|
||||||
|
):
|
||||||
|
"""Assert that an exception which occurs during installation is properly raised.
|
||||||
|
|
||||||
|
Regression test for https://github.com/enpaul/tox-poetry-installer/issues/86
|
||||||
|
"""
|
||||||
|
from tox_poetry_installer import _poetry # pylint: disable=import-outside-toplevel
|
||||||
|
|
||||||
|
poetry = Factory().create_poetry(None)
|
||||||
|
packages: utilities.PackageMap = {
|
||||||
|
item.name: item for item in poetry.locker.locked_repository().packages
|
||||||
|
}
|
||||||
|
to_install = [packages["toml"]]
|
||||||
|
venv = tox.venv.VirtualEnv()
|
||||||
|
fake_exception = ValueError("my testing exception")
|
||||||
|
|
||||||
|
with mock.patch.object(
|
||||||
|
_poetry,
|
||||||
|
"PipInstaller",
|
||||||
|
**{"return_value.install.side_effect": fake_exception},
|
||||||
|
):
|
||||||
|
with pytest.raises(ValueError) as exc_info:
|
||||||
|
installer.install(poetry, venv, to_install, num_threads)
|
||||||
|
|
||||||
|
assert exc_info.value is fake_exception
|
||||||
|
@ -71,11 +71,20 @@ def install(
|
|||||||
yield lambda func, arg: func(arg)
|
yield lambda func, arg: func(arg)
|
||||||
|
|
||||||
with _optional_parallelize() as executor:
|
with _optional_parallelize() as executor:
|
||||||
|
futures = []
|
||||||
for dependency in packages:
|
for dependency in packages:
|
||||||
if dependency not in installed:
|
if dependency not in installed:
|
||||||
installed.add(dependency)
|
installed.add(dependency)
|
||||||
logger.debug(f"Queuing {dependency}")
|
logger.debug(f"Queuing {dependency}")
|
||||||
executor(logged_install, dependency)
|
future = executor(logged_install, dependency)
|
||||||
|
if future is not None:
|
||||||
|
futures.append(future)
|
||||||
else:
|
else:
|
||||||
logger.debug(f"Skipping {dependency}, already installed")
|
logger.debug(f"Skipping {dependency}, already installed")
|
||||||
logger.debug("Waiting for installs to finish...")
|
logger.debug("Waiting for installs to finish...")
|
||||||
|
|
||||||
|
for future in concurrent.futures.as_completed(futures):
|
||||||
|
# Don't actually care about the return value, just waiting on the
|
||||||
|
# future to ensure any exceptions that were raised in the called
|
||||||
|
# function are propagated.
|
||||||
|
future.result()
|
||||||
|
Loading…
Reference in New Issue
Block a user