<div dir="ltr">Hi Anatoly, Holger,<div><br></div><div>On Sun, Sep 28, 2014 at 6:38 PM, Anatoly Bubenkov <span dir="ltr"><<a href="mailto:bubenkoff@gmail.com" target="_blank">bubenkoff@gmail.com</a>></span> wrote:</div><div>> I had the same problem solved it by 'deferring' a plugin hook a bit:</div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Thanks! I will use this approach.</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div>On Mon, Sep 29, 2014 at 3:47 AM, holger krekel <span dir="ltr"><<a href="mailto:holger@merlinux.eu" target="_blank">holger@merlinux.eu</a>></span> wrote:</div><div>> So currently i think it's best to just add an example to the docs.</div><div><br></div><div>OK, I will open a PR with an example targeted to plugin developers.</div><div><br></div><div>Thanks for the help!</div><div><br></div><div>Cheers,</div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 29, 2014 at 3:47 AM, holger krekel <span dir="ltr"><<a href="mailto:holger@merlinux.eu" target="_blank">holger@merlinux.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Bruno, Anatoly,<br>
<div><div class="h5"><br>
On Sun, Sep 28, 2014 at 17:46 -0300, Bruno Oliveira wrote:<br>
> Hi everyone,<br>
><br>
> I'm having some trouble when trying to use some of xdist-defined hooks in a<br>
> plugin, but I believe this problem is not related to xdist specifically.<br>
><br>
> If I redefine a few of `xdist`'s hook functions inside a conftest file, it<br>
> works fine. Once I move them to an external plugin however, I start getting<br>
> "found unknown hook" errors.<br>
><br>
> Here is an example:<br>
><br>
>     # contents of conftest.py<br>
>     def pytest_configure_node(node):<br>
>         assert 0, 'configure_node called'<br>
><br>
>     # contents of test_foo.py<br>
>     def test_foo(): pass<br>
><br>
> In a fresh virtual environment with `pytest-xdist` installed:<br>
><br>
><br>
>     $ py.test -n2<br>
>     <snip traceback><br>
>     INTERNALERROR> AssertionError: configure_node called<br>
><br>
> OK, that's what I expected.<br>
><br>
> On the other hand, renaming `conftest.py` to `myplugin.py`:<br>
><br>
>     $ py.test -n2 -p myplugin<br>
>         raise PluginValidationError("%s:\n%s" % (name, stringio.getvalue()))<br>
>     _pytest.helpconfig.PluginValidationError: myplugin:<br>
>     found unknown hook: pytest_configure_node<br>
><br>
> (You might have to configure your $PYTHONPATH to the working directory)<br>
><br>
> The same happens if I make a plugin using <a href="http://setup.py/setuptools" target="_blank">setup.py/setuptools</a>.<br>
><br>
> Am I missing something, or is this a bug?<br>
><br>
> Digging at the source a bit I found that plugin registration and hook<br>
> validation happen one right after the other, which might be a problem<br>
> because a plugin might depend on hooks that will be registered by other<br>
> plugins later.<br>
<br>
</div></div>You are right.  We could do it differently by first calling pytest_addhooks<br>
on all plugins before calling the pytest_registered hook.  But Anatoly's<br>
solution (deferring registration to pytest_configure) has the additional<br>
advantage that you can conditionally register plugins.  You might register<br>
differently (or not at all) if there is no xdist installed, for example.<br>
So currently i think it's best to just add an example to the docs.<br>
<br>
best,<br>
holge<br>
<div class=""><div class="h5"><br>
<br>
<br>
> Cheers,<br>
> Bruno.<br>
<br>
> _______________________________________________<br>
> Pytest-dev mailing list<br>
> <a href="mailto:Pytest-dev@python.org">Pytest-dev@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/pytest-dev" target="_blank">https://mail.python.org/mailman/listinfo/pytest-dev</a><br>
<br>
</div></div></blockquote></div><br></div></div>