Giter VIP home page Giter VIP logo

nvim-pytrize.lua's Introduction

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:

  • Populates virtual text at the entries of pytest.mark.parametrize (see gif above), such that you can easily see which one is which. Done by calling Pytrize (and PytrizeClear to clear them). Alternatively lua require('pytrize.api').set() (and lua require('pytrize.api').clear()).
  • Provides a command to jump to the corresponding entry in pytest.mark.parametrize based on the test-case id under the cursor (see gif above). Done by calling PytrizeJump. Alternatively lua require('pytrize.api').jump(). See the Input-section below for cases where the file-path is not available.
  • Provides a command to jump to the declaration of the fixture under the cursor (by name), see fixture below. Done by calling PytrizeJumpFixture. Alternatively lua require('pytrize.api').jump_fixture().

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:

  • no_commands can be set to true and the commands Pytrize etc won't be declared.
  • highlight defines the highlighting used for the virtual text.
  • preferred_input which method to query input to prefer (if it's installed), see the Input-section below.

Details

  • pytests cache is used to find the test-case ids (eg test.py::test[None2-a1-b-c1-8]) which means that the tests have to be run at least once. Also old ids might confuse pytrize, but you can clear the cache with pytest --cache-clear.
  • treesitter is used to find the correct entry in pytest.mark.parametrize.

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:

nvim-pytrize.lua's People

Contributors

acksld avatar torarvid avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.