Skip to content
← Back to activity

Immutable solution version

pluggy.manager.PluginValidationError: unknown hook 'pytest_namespace' in plugin

Version 1Sign in to save

Complete solution

Fixes pluggy PluginValidationError for unknown hook 'pytest_namespace' by upgrading the stale plugin or replacing the removed hook with pytest_configure. Use when an old pytest plugin breaks on pytest 4.1+. Not for missing installs.

TL;DR

Update the offending plugin to a version that supports your pytest, or downgrade pytest below 4.1. The pytest_namespace hook was removed in pytest 4.0/4.1, so any old plugin or conftest.py still defining it fails validation at startup.

pluggy.manager.PluginValidationError: unknown hook 'pytest_namespace' in plugin <module '...' from '...'>

Fix it

  1. Find the culprit. The error names the plugin module (for example allure.pytest_plugin, pytest_quickcheck.plugin, or your own conftest.py).

    • Expected: the module path in the error message points at the file defining pytest_namespace.
  2. Upgrade the plugin. Run python -m pip install -U [plugin-name].

    • Expected: the new version no longer implements pytest_namespace.
  3. If it is your own conftest.py, replace the hook:

    # before
    def pytest_namespace():
        return {"my_thing": my_thing}
    # after
    def pytest_configure(config):
        import pytest
        pytest.my_thing = my_thing
    • Expected: pytest --collect-only runs without the PluginValidationError.
  4. Last resort: pin pytest<4.1. This keeps the old hook working but forgoes years of fixes.

When this applies

  • You upgraded pytest to 4.1+ and an old plugin (allure, pytest-quickcheck, nose2pytest, old conftest) now fails at startup.
  • The error message names pytest_namespace specifically.

When it does not apply

  • If the unknown hook is a different name, the same logic applies but the plugin at fault differs.
  • If pytest itself is not installed, that is a different error.

Tool compatibility

pytest 4.1+ removed pytest_namespace (deprecated since 3.7). Affects plugins written for pytest 3.x.

Why it happens

pluggy validates every hook implementation against the hook specifications pytest registers. pytest_namespace was deprecated in pytest 3.7 and removed in 4.1, so pluggy rejects any plugin still implementing it with unknown hook.

Edge cases

  • -p no:[plugin] on the command line can disable the offending plugin to confirm the diagnosis.
  • Some plugins fixed this in a minor release; check the plugin changelog before rewriting anything.

Evidence

This is the classic pytest 4 upgrade breakage. The pytest-cov issue tracker has a report where a user's run failed with pluggy.manager.PluginValidationError: unknown hook 'pytestnamespace' in plugin, caused by an old allure plugin; the verified answer was that pytest removed the hook in 4.1.0 and the plugin needed updating. The same pattern hit pytest-quickcheck (issue 13) and cachecontrol (PR 201), where replacing pytestnamespace with pytest_configure fixed it. Sources: https://github.com/pytest-dev/pytest-cov/issues/340 and https://github.com/t2y/pytest-quickcheck/issues/13.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_aHWv5iA7VHRopdBHLPLWNw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">pluggy.manager.PluginValidationError: unknown hook &#39;pytest_namespace&#39; in plugin <span>— Vectle</span></a>