[TIP] pytest: How to implement a new hook that only operates on subdirectories?
daniel.wandschneider at schrodinger.com
Tue Nov 15 16:57:59 PST 2016
I'd like to implement a pytest hook that allows test directories to have an
"owner". All subdirs of a test directory should be owned by the same
person, unless that directory is itself owned.
I thought that this would work:
Specify the owner of tests in this directory.
@return: a username
then use like:
def pytest_runtest_makereport(item, call):
"""Add the test owner to each report."""
report = _pytest.runner.pytest_runtest_makereport(item, call)
if not report.passed:
owner = item.ihook.pytest_test_owner()
report.sections.append(('owner: ' + owner))
However, this *actually* sets the owner to whichever conftest was imported
last. The pytest hook docs say "Session and test running activities will
invoke all hooks defined in conftest.py files closer to the root of the
filesystem." (pytest docs
How can I get similar behavior for my new hook?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python