Troubleshooting

“Can't perform this operation for unregistered loader type”

When running a test suite using pytest, pkg_resources may raise this error when attempting to load something like an extension or another entry point.

Tracing this shows that a NullProvider is being used instead of a DefaultProvider for loading the resource. This is set on <module>.__loader__. Further tracing indicates that pytest is creating its own import hook in order to rewrite asserts, and is breaking pkg_resources.

This is sort of true, but also not that simple. It does this for any module defining a plugin, and any child modules of that. That means that if you define a plugin in a root conftest.py, all child modules will have asserts rewritten, and therefore anything within that needs to be loaded via pkg_resources will break.

The solution is to ensure that any plugins registered are in some other package or module, so that this assertion rewriting behavior won’t filter up to children.

See: