def test_hook_with_addoption(self, pytester: Pytester) -> None:
        """Test that hooks can be used in a call to pytest_addoption"""
        pytester.makepyfile(
            newhooks="""
            import pytest
            @pytest.hookspec(firstresult=True)
            def pytest_default_value():
                pass
        """
        )
        pytester.makepyfile(
            myplugin="""
            import newhooks
            def pytest_addhooks(pluginmanager):
                pluginmanager.add_hookspecs(newhooks)
            def pytest_addoption(parser, pluginmanager):
                default_value = pluginmanager.hook.pytest_default_value()
                parser.addoption("--config", help="Config, defaults to %(default)s", default=default_value)
        """
        )
        pytester.makeconftest(
            """
            pytest_plugins=("myplugin",)
            def pytest_default_value():
                return "default_value"
        """
        )
        res = pytester.runpytest("--help")
        res.stdout.fnmatch_lines(["*--config=CONFIG*default_value*"])
Test that hooks can be used in a call to pytest_addoption
testing/test_pluginmanager.py