[WIP] Make plugin compatible with tox v4

This commit is contained in:
Obeida Shamoun
2023-01-10 03:34:35 +01:00
parent c55ba474c7
commit a94933e7ef
8 changed files with 101 additions and 236 deletions

View File

@@ -6,7 +6,7 @@ import poetry.factory
import poetry.installation.pip_installer
import poetry.utils.env
import pytest
import tox
import tox.tox_env.python.virtual_env.runner
from poetry.core.packages.package import Package as PoetryPackage
from tox_poetry_installer import utilities
@@ -20,11 +20,8 @@ FAKE_VENV_PATH = Path("nowhere")
class MockVirtualEnv:
"""Mock class for the :class:`poetry.utils.env.VirtualEnv` and :class:`tox.venv.VirtualEnv`"""
class MockTestenvConfig: # pylint: disable=missing-class-docstring
envdir = FAKE_VENV_PATH
def __init__(self, *args, **kwargs):
self.envconfig = self.MockTestenvConfig()
self.env_dir = FAKE_VENV_PATH
self.installed = []
@staticmethod
@@ -53,7 +50,9 @@ def mock_venv(monkeypatch):
monkeypatch.setattr(
poetry.installation.pip_installer, "PipInstaller", MockPipInstaller
)
monkeypatch.setattr(tox.venv, "VirtualEnv", MockVirtualEnv)
monkeypatch.setattr(
tox.tox_env.python.virtual_env.runner, "VirtualEnvRunner", MockVirtualEnv
)
monkeypatch.setattr(poetry.utils.env, "VirtualEnv", MockVirtualEnv)

View File

@@ -3,7 +3,7 @@ import time
from unittest import mock
import pytest
import tox.venv
import tox.tox_env.python.virtual_env.runner
from poetry.factory import Factory
from .fixtures import mock_poetry_factory
@@ -19,7 +19,7 @@ def test_deduplication(mock_venv, mock_poetry_factory):
item.name: item for item in poetry.locker.locked_repository().packages
}
venv = tox.venv.VirtualEnv()
venv = tox.tox_env.python.virtual_env.runner.VirtualEnvRunner()
to_install = [packages["toml"], packages["toml"]]
installer.install(poetry, venv, to_install)
@@ -43,12 +43,12 @@ def test_parallelization(mock_venv, mock_poetry_factory):
packages["attrs"],
]
venv_sequential = tox.venv.VirtualEnv()
venv_sequential = tox.tox_env.python.virtual_env.runner.VirtualEnvRunner()
start_sequential = time.time()
installer.install(poetry, venv_sequential, to_install, 0)
sequential = time.time() - start_sequential
venv_parallel = tox.venv.VirtualEnv()
venv_parallel = tox.tox_env.python.virtual_env.runner.VirtualEnvRunner()
start_parallel = time.time()
installer.install(poetry, venv_parallel, to_install, 5)
parallel = time.time() - start_parallel
@@ -76,7 +76,7 @@ def test_propagates_exceptions_during_installation(
item.name: item for item in poetry.locker.locked_repository().packages
}
to_install = [packages["toml"]]
venv = tox.venv.VirtualEnv()
venv = tox.tox_env.python.virtual_env.runner.VirtualEnvRunner()
fake_exception = ValueError("my testing exception")
with mock.patch.object(