Home

Awesome

Pytrize

Short summary

Helps navigating pytest.mark.parametrize entries and fixtures by virtual text and jump to declaration commands, using pytests cache and treesitter.

pytrize

What problems does this plugin solve?

Parametrize

pytest is amazing! The only thing that bothers me from time to time is if there are many entries in the parametrization of the test. If a test fails you might see for example:

test.py::test[None2-a1-b-c1-8]

Now you want to see what test case this actually corresponds to. What I sometimes do is to go to the entries in pytest.mark.parametrize and count the entries until I'm at the right one. But this is really not nice and easy to make a mistake, we should let the computer do this for us.

Enter pytrize.

Fixture

Another issue is knowing where a certain fixture is defined and what it does.

What does the plugin do?

Three things:

Installation

For example using packer:

use { -- pytrize {{{
  'AckslD/nvim-pytrize.lua',
  -- uncomment if you want to lazy load
  -- cmd = {'Pytrize', 'PytrizeClear', 'PytrizeJump'},
  -- uncomment if you want to lazy load but not use the commands
  -- module = 'pytrize',
  config = 'require("pytrize").setup()',
} -- }}}

Requires plenary.nvim.

Configuration

require("pytrize").setup takes an optional table of settings which currently have the default values:

{
  no_commands = false,
  highlight = 'LineNr',
  preferred_input = 'telescope',
}

where:

Details

Jump to fixture

To jump to the declaration of a fixture under the cursor, do PytrizeJumpFixture: pytrize_fixture

Input

In some cases the file-path is not printed by pytest, for example when a test fails when it might look something like:


_________________________________ test[None2-a1-b-c1-9] _________________________________

or similar. If you trigger to jump to the declaration of the parameters in this case pytrize will find all files in the cache that matches this test-case id and if there is more than one ask you which one to jump to. Currently three input methods are supported: