[pytest-dev] Hook validation difference between conftest files and plugins
Bruno Oliveira
nicoddemus at gmail.com
Sun Sep 28 22:46:00 CEST 2014
Hi everyone,
I'm having some trouble when trying to use some of xdist-defined hooks in a
plugin, but I believe this problem is not related to xdist specifically.
If I redefine a few of `xdist`'s hook functions inside a conftest file, it
works fine. Once I move them to an external plugin however, I start getting
"found unknown hook" errors.
Here is an example:
# contents of conftest.py
def pytest_configure_node(node):
assert 0, 'configure_node called'
# contents of test_foo.py
def test_foo(): pass
In a fresh virtual environment with `pytest-xdist` installed:
$ py.test -n2
<snip traceback>
INTERNALERROR> AssertionError: configure_node called
OK, that's what I expected.
On the other hand, renaming `conftest.py` to `myplugin.py`:
$ py.test -n2 -p myplugin
raise PluginValidationError("%s:\n%s" % (name, stringio.getvalue()))
_pytest.helpconfig.PluginValidationError: myplugin:
found unknown hook: pytest_configure_node
(You might have to configure your $PYTHONPATH to the working directory)
The same happens if I make a plugin using setup.py/setuptools.
Am I missing something, or is this a bug?
Digging at the source a bit I found that plugin registration and hook
validation happen one right after the other, which might be a problem
because a plugin might depend on hooks that will be registered by other
plugins later.
Cheers,
Bruno.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20140928/348d2120/attachment.html>
More information about the Pytest-dev
mailing list