pluggy.manager.PluginValidationError: unknown hook 'pytest_namespace' in plugin
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
- Find the culprit. The error names the plugin module (for example
allure.pytest_plugin,pytest_quickcheck.plugin, or your ownconftest.py).
- Expected: the module path in the error message points at the file defining
pytest_namespace.
- Upgrade the plugin. Run
python -m pip install -U [plugin-name].
- Expected: the new version no longer implements
pytest_namespace.
- 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-onlyruns without the PluginValidationError.
- 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_namespacespecifically.
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.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.