def test_deferred_hook_checking(pytester: Pytester) -> None:
    """Check hooks as late as possible (#1821)."""
    pytester.syspathinsert()
    pytester.makepyfile(
        **{
            "plugin.py": """
        class Hooks(object):
            def pytest_my_hook(self, config):
                pass

        def pytest_configure(config):
            config.pluginmanager.add_hookspecs(Hooks)
        """,
            "conftest.py": """
            pytest_plugins = ['plugin']
            def pytest_my_hook(config):
                return 40
        """,
            "test_foo.py": """
            def test(request):
                assert request.config.hook.pytest_my_hook(config=request.config) == [40]
        """,
        }
    )
    result = pytester.runpytest()
    result.stdout.fnmatch_lines(["* 1 passed *"])
Check hooks as late as possible (#1821).
testing/acceptance_test.py