|
37 | 37 | from tox.execute.api import Execute, ExecuteInstance, ExecuteOptions, ExecuteStatus, Outcome
|
38 | 38 | from tox.execute.request import ExecuteRequest, shell_cmd
|
39 | 39 | from tox.execute.stream import SyncWrite
|
| 40 | +from tox.plugin import manager |
40 | 41 | from tox.report import LOGGER, OutErr
|
41 | 42 | from tox.run import run as tox_run
|
42 | 43 | from tox.run import setup_state as previous_setup_state
|
@@ -74,12 +75,19 @@ def ensure_logging_framework_not_altered() -> Iterator[None]: # noqa: PT004
|
74 | 75 | def _disable_root_tox_py(request: SubRequest, mocker: MockerFixture) -> Iterator[None]:
|
75 | 76 | """unless this is a plugin test do not allow loading toxfile.py"""
|
76 | 77 | if request.node.get_closest_marker("plugin_test"): # unregister inline plugin
|
77 |
| - from tox.plugin import manager |
| 78 | + module, load_inline = None, manager._load_inline |
78 | 79 |
|
79 |
| - inline_plugin = mocker.spy(manager, "_load_inline") |
| 80 | + def _load_inline(path: Path) -> Optional[ModuleType]: # register only on first run, and unregister at end |
| 81 | + nonlocal module |
| 82 | + if module is None: |
| 83 | + module = load_inline(path) |
| 84 | + return module |
| 85 | + return None |
| 86 | + |
| 87 | + mocker.patch.object(manager, "_load_inline", _load_inline) |
80 | 88 | yield
|
81 |
| - if inline_plugin.spy_return is not None: # pragma: no branch |
82 |
| - manager.MANAGER.manager.unregister(inline_plugin.spy_return) |
| 89 | + if module is not None: # pragma: no branch |
| 90 | + manager.MANAGER.manager.unregister(module) |
83 | 91 | else: # do not allow loading inline plugins
|
84 | 92 | mocker.patch("tox.plugin.inline._load_plugin", return_value=None)
|
85 | 93 | yield
|
@@ -605,7 +613,7 @@ def enable_pip_pypi_access_fixture(
|
605 | 613 | return previous_url
|
606 | 614 |
|
607 | 615 |
|
608 |
| -def register_inline_plugin(mocker: MockerFixture, *args: Callable[..., Any]) -> None: # |
| 616 | +def register_inline_plugin(mocker: MockerFixture, *args: Callable[..., Any]) -> None: |
609 | 617 | frame_info = inspect.stack()[1]
|
610 | 618 | caller_module = inspect.getmodule(frame_info[0])
|
611 | 619 | assert caller_module is not None
|
|
0 commit comments