Pytest hooks¶
BetterPy treats pytest hook functions as first-class symbols: it generates hook stubs where pytest actually discovers them, links implementations back to the hook specification, and shows the hook documentation inline.
Generate a hook implementation¶
Generate pytest hook inserts a hook implementation into the file pytest loads hooks from, such as the nearest conftest.py or a plugin module. The generated function is opened as a live template, so the parameter list and body can be adjusted immediately after insertion.
Navigation and documentation¶
- A gutter marker next to a hook implementation leads to the hook specification and to other implementations of the same hook.
- Hook navigation discovers implementations in files matched by the active pytest
python_filespatterns as well asconftest.pyand plugin modules. - Go to Declaration on a hook implementation in
conftest.pyresolves to the corresponding hook specification shipped with pytest. - Quick documentation renders the hook's documented contract, including its parameters and expected return value.
- Hook names are real references in
conftest.py, so renaming and Find Usages cover implementations acrossconftest.pyfiles.
Notes¶
- Hook generation follows pytest's own locations, including
conftest.pyancestry,pytest_pluginsdeclarations, and plugin modules. Navigation and reference-based rename/Find Usages currently apply toconftest.pyimplementations. - The feature can be toggled in Settings | Tools | BetterPy | Testing (Pytest) | Fixtures.