|
10 | 10 | import re |
11 | 11 | import sys |
12 | 12 | import textwrap |
| 13 | +import types |
13 | 14 | from typing import Any |
14 | 15 |
|
15 | 16 | import _pytest._code |
|
30 | 31 | from _pytest.monkeypatch import MonkeyPatch |
31 | 32 | from _pytest.pathlib import absolutepath |
32 | 33 | from _pytest.pytester import Pytester |
| 34 | +from _pytest.warning_types import PytestConfigWarning |
33 | 35 | from _pytest.warning_types import PytestDeprecationWarning |
34 | 36 | import pytest |
35 | 37 |
|
@@ -1690,6 +1692,50 @@ def distributions(): |
1690 | 1692 | # __spec__ is present when testing locally on pypy, but not in CI ???? |
1691 | 1693 |
|
1692 | 1694 |
|
| 1695 | +def test_disable_plugin_autoload_warns_for_submodule_entrypoint( |
| 1696 | + pytester: Pytester, monkeypatch: MonkeyPatch |
| 1697 | +) -> None: |
| 1698 | + class DummyEntryPoint: |
| 1699 | + project_name = "pytest-recording" |
| 1700 | + name = "recording" |
| 1701 | + group = "pytest11" |
| 1702 | + version = "1.0" |
| 1703 | + value = "pytest_recording.plugin" |
| 1704 | + |
| 1705 | + def load(self): |
| 1706 | + return sys.modules[self.value] |
| 1707 | + |
| 1708 | + class Distribution: |
| 1709 | + metadata = {"name": "pytest-recording"} |
| 1710 | + entry_points = (DummyEntryPoint(),) |
| 1711 | + files = () |
| 1712 | + |
| 1713 | + def distributions(): |
| 1714 | + return (Distribution(),) |
| 1715 | + |
| 1716 | + top_level_plugin = types.ModuleType("pytest_recording") |
| 1717 | + submodule_plugin = types.ModuleType("pytest_recording.plugin") |
| 1718 | + |
| 1719 | + def pytest_addoption(parser): |
| 1720 | + parser.addoption("--block-network") |
| 1721 | + |
| 1722 | + setattr(submodule_plugin, "pytest_addoption", pytest_addoption) |
| 1723 | + |
| 1724 | + monkeypatch.setattr(importlib.metadata, "distributions", distributions) |
| 1725 | + monkeypatch.setitem(sys.modules, "pytest_recording", top_level_plugin) |
| 1726 | + monkeypatch.setitem(sys.modules, "pytest_recording.plugin", submodule_plugin) |
| 1727 | + |
| 1728 | + with pytest.warns( |
| 1729 | + PytestConfigWarning, |
| 1730 | + match=r'Plugin "pytest_recording" contains no pytest hooks\. Did you mean to use -p recording\?', |
| 1731 | + ): |
| 1732 | + config = pytester.parseconfig( |
| 1733 | + "--disable-plugin-autoload", "-p", "pytest_recording" |
| 1734 | + ) |
| 1735 | + |
| 1736 | + assert config.pluginmanager.get_plugin("pytest_recording") is not None |
| 1737 | + |
| 1738 | + |
1693 | 1739 | def test_plugin_loading_order(pytester: Pytester) -> None: |
1694 | 1740 | """Test order of plugin loading with `-p`.""" |
1695 | 1741 | p1 = pytester.makepyfile( |
|
0 commit comments