Easily jump to pytest fixtures. Supports jumping to a fixture used by the test under cursor, jumping to any test defined in the current project, or reverse lookup -- i.e. jump to a test which uses a fixture.
lazy.nvim:
{
"sfrieds3/pytest_fixtures.nvim",
opts = {
-- configuration goes here
-- see the [configuration](#configuration) section below for options
},
dependencies = {
"nvim-lua/plenary.nvim"
}
},
First, ensure you are in an environment with pytest
installed. Then, when your cursor is on a test, hit <localleader>]
(default mapping, see configuration section below to override the default mapping) to bring up a floating window with a list of fixtures used by the current test. Selecting any one will bring you to the soruce for that test. Simple as that.
Additionally, the plugin allows you to list all project fixtures, and either go to the fixture or list and go to a test using that fixture. See the user commands secion for more details.
-
PytestFixturesTestFixtures
: List fixtures used by the test under cursor and go to fixture on selection -
PytestFixturesProjectFixtures
: List all project fixtures, and go to fixture on selection -
PytestFixturesReverseLookup
: List all tests using a selected fixture, and go to test on selection -
PytestFixturesProjectCachePath
: Echo the project cache path -
PytestFixturesRefresh
: Refresh fixture cache, you should not need to run this if you have configured autocmd setup
Default configuration
{
-- set keymaps
keymaps = { -- set keymaps for user commands generated by the plugin
["<localleader>]"] = "PytestFixturesTestFixtures",
["<localleader>}"] = "PytestFixturesProjectFixtures",
},
-- controls whether or not to create user commands
create_user_commands = true,
-- configure autocmd events for which to execute a refresh of the fixture cache
refresh_events = { "BufEnter", "BufWinEnter", "BufWritePost" },
-- configure files/directories to use for determining the project root
project_markers = { ".git", "pyproject.toml", "setup.py", "setup.cfg" },
-- configure the path to store the fixture cache
data_path = string.format("%s/pytest_fixtures", vim.fn.stdpath("data")),
}