|
13 | 13 | from tox.config.sets import ConfigSet, CoreConfigSet, EnvConfigSet |
14 | 14 | from tox.execute import Outcome |
15 | 15 | from tox.plugin import impl |
| 16 | +from tox.plugin.manager import Plugin |
16 | 17 | from tox.pytest import ToxProjectCreator, register_inline_plugin |
17 | 18 | from tox.session.state import State |
18 | 19 | from tox.tox_env.api import ToxEnv |
|
21 | 22 | if TYPE_CHECKING: |
22 | 23 | from pathlib import Path |
23 | 24 |
|
| 25 | + from pluggy import PluginManager |
24 | 26 | from pytest_mock import MockerFixture |
25 | 27 |
|
26 | 28 |
|
@@ -268,3 +270,45 @@ def tox_after_run_commands(tox_env: ToxEnv, exit_code: int, outcomes: list[Outco |
268 | 270 | project = tox_project({"tox.ini": "[testenv]\npackage=skip"}) |
269 | 271 | result = project.run("r") |
270 | 272 | result.assert_success() |
| 273 | + |
| 274 | + |
| 275 | +@pytest.mark.parametrize( |
| 276 | + ("env_val", "expect_a", "expect_b"), |
| 277 | + [ |
| 278 | + pytest.param("", True, True, id="none_disabled"), |
| 279 | + pytest.param("dummy_plugin_a,dummy_plugin_b", False, False, id="both_disabled"), |
| 280 | + pytest.param("dummy_plugin_a", False, True, id="only_a_disabled"), |
| 281 | + pytest.param("dummy_plugin_b", True, False, id="only_b_disabled"), |
| 282 | + ], |
| 283 | +) |
| 284 | +def test_disable_external_plugins( |
| 285 | + tox_project: ToxProjectCreator, |
| 286 | + mocker: MockerFixture, |
| 287 | + env_val: str, |
| 288 | + expect_a: bool, |
| 289 | + expect_b: bool, |
| 290 | +) -> None: |
| 291 | + class DummyPluginA: |
| 292 | + @staticmethod |
| 293 | + @impl |
| 294 | + def tox_add_option(parser: ToxParser) -> None: # noqa: ARG004 |
| 295 | + logging.warning("dummy plugin A called") |
| 296 | + |
| 297 | + class DummyPluginB: |
| 298 | + @staticmethod |
| 299 | + @impl |
| 300 | + def tox_add_option(parser: ToxParser) -> None: # noqa: ARG004 |
| 301 | + logging.warning("dummy plugin B called") |
| 302 | + |
| 303 | + def fake_load_entrypoints(self: PluginManager, name: str) -> None: # noqa: ARG001 |
| 304 | + self.register(DummyPluginA(), name="dummy_plugin_a") |
| 305 | + self.register(DummyPluginB(), name="dummy_plugin_b") |
| 306 | + |
| 307 | + mocker.patch("pluggy.PluginManager.load_setuptools_entrypoints", fake_load_entrypoints) |
| 308 | + mocker.patch.dict(os.environ, {"TOX_DISABLED_EXTERNAL_PLUGINS": env_val}) |
| 309 | + mocker.patch("tox.plugin.manager.MANAGER", Plugin()) |
| 310 | + project = tox_project({"tox.ini": ""}) |
| 311 | + result = project.run("--version") |
| 312 | + result.assert_success() |
| 313 | + assert ("dummy plugin A called" in result.out) == expect_a |
| 314 | + assert ("dummy plugin B called" in result.out) == expect_b |
0 commit comments