pytest_runtest_call() runs item twice #8868
-
When I define This is bad for two reasons:
A toy example is below:
Output:
You'll note that the "Passed the global check" statement happened, which means the test already ran once (and passed) before failing this second time. Installed packages (developing an internal app using poetry, so here are the contents of our pyproject.toml file:
pytest version: 6.2.4 (see pyproject.toml)
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
When multiple plugins implement a hook, pytest calls all of them (unless the hook is defined as In your example, you should be able to just remove the @pytest.hookimpl(trylast=True)
def pytest_runtest_call(item):
... Let me know if it's not clear or doesn't work as expected. |
Beta Was this translation helpful? Give feedback.
When multiple plugins implement a hook, pytest calls all of them (unless the hook is defined as
firstresult
, whichpytest_runtest_call
isn't). This means pytest calls your hook implementation in addition to the built-in pytest implementation.In your example, you should be able to just remove the
item.runtest()
call as pytest already does that. To make sure your hook implementation runs after all of the others, you can mark it astrylast=True
:Let me know if it's not clear or doesn't work as expected.