<div dir="ltr">I&#39;d like to implement a pytest hook that allows test directories to have an &quot;owner&quot;. All subdirs of a test directory should be owned by the same person, unless that directory is itself owned.<div><br></div><div>I thought that this would work:</div><div><br></div><div><font face="monospace, monospace">class newhooks:</font></div><div><div><font face="monospace, monospace">     @staticmethod</font></div><div><font face="monospace, monospace">     @hookspec(firstresult=True)<br></font></div><div><font face="monospace, monospace">     def pytest_test_owner():</font></div><div><font face="monospace, monospace">         &quot;&quot;&quot;</font></div><div><font face="monospace, monospace">         Specify the owner of tests in this directory.</font></div><div><font face="monospace, monospace">         @return: a username</font></div><div><font face="monospace, monospace">         &quot;&quot;&quot;</font></div></div><div><font face="monospace, monospace">         pass</font></div><div><font face="monospace, monospace">pluginmanager.add_hookspecs(newhooks)</font><br></div><div><br></div><div>then use like:</div><div><br></div><div><div><font face="monospace, monospace">def pytest_runtest_makereport(item, call):</font></div><div><font face="monospace, monospace">    &quot;&quot;&quot;Add the test owner to each report.&quot;&quot;&quot;</font></div><div><font face="monospace, monospace">    report = _pytest.runner.pytest_runtest_makereport(item, call)</font></div><div><font face="monospace, monospace">    if not report.passed:</font></div><div><font face="monospace, monospace">        owner = item.ihook.pytest_test_owner()</font></div></div><div><font face="monospace, monospace">        if owner:</font></div><div><font face="monospace, monospace">            report.sections.append((&#39;owner: &#39; + owner))</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">However, this <i>actually</i> sets the owner to whichever conftest was imported last. The pytest hook docs say &quot;Session and test running activities will invoke all hooks defined in conftest.py files closer to the root of the filesystem.&quot; (<a href="http://pytest.org/2.2.4/plugins.html#conftest-py-local-per-directory-plugins">pytest docs</a>) How can I get similar behavior for my new hook?</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div></div>