Skip to content

Commit 3a47715

Browse files
refactor: remove pytest parametrize support, keep fixture features only
Remove all modules related to pytest.mark.parametrize and pytest cache: - Delete call_spec.lua, nodeids.lua, marks.lua, strings.lua, tables.lua - Delete jump/param.lua and its tests - Remove Pytrize, PytrizeClear, PytrizeJump commands - Remove .pytest_cache and pytest.ini from root markers - Remove get_nodeids_path from paths.lua - Update rename test to use .git instead of .pytest_cache as root marker - Rewrite README to focus on fixture features only
1 parent 3d545cd commit 3a47715

16 files changed

Lines changed: 37 additions & 890 deletions

README.md

Lines changed: 14 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,41 @@
22

33
## Short summary
44

5-
Helps navigating `pytest.mark.parametrize` entries and fixtures by virtual text and jump to declaration commands, using `pytest`s cache and `treesitter`.
6-
7-
![pytrize](https://user-images.githubusercontent.com/23341710/143510539-c025925c-0e4c-4990-83ab-1c0da076c0f8.gif)
8-
9-
## What problems does this plugin solve?
10-
11-
### Parametrize
12-
13-
`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.
14-
If a test fails you might see for example:
15-
16-
```
17-
test.py::test[None2-a1-b-c1-8]
18-
```
19-
20-
Now you want to see what test case this actually corresponds to.
21-
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.
22-
But this is really not nice and easy to make a mistake, we should let the computer do this for us.
23-
24-
Enter `pytrize`.
25-
26-
### Fixture
27-
28-
Another issue is knowing where a certain fixture is defined and what it does.
5+
Helps navigating pytest fixtures by providing jump to declaration, rename, and find usages commands, using `treesitter`.
296

307
## What does the plugin do?
318

32-
Several things:
33-
34-
- Populates virtual text at the entries of `pytest.mark.parametrize` (see gif above), such that you can easily see which one is which.
35-
Done by calling `Pytrize` (and `PytrizeClear` to clear them).
36-
Alternatively `lua require('pytrize.api').set()` (and `lua require('pytrize.api').clear()`).
37-
- 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).
38-
Done by calling `PytrizeJump`.
39-
Alternatively `lua require('pytrize.api').jump()`.
40-
See the [Input](#input)-section below for cases where the file-path is not available.
41-
- Provides a command to jump to the declaration of the fixture under the cursor (by name), see [fixture](#jump-to-fixture) below.
9+
- **Jump to fixture definition** — jump to the declaration of the fixture under the cursor.
4210
Done by calling `PytrizeJumpFixture`.
4311
Alternatively `lua require('pytrize.api').jump_fixture()`.
44-
- Provides a command to rename the fixture under the cursor (by name), see [fixture](#rename-fixture) below.
12+
See [Jump to fixture](#jump-to-fixture) below.
13+
- **Rename fixture** — rename the fixture under the cursor across the project.
4514
Done by calling `PytrizeRenameFixture`.
4615
Alternatively `lua require('pytrize.api').rename_fixture()`.
47-
- Provides a command to find all usages of the fixture under the cursor across the project, see [fixture usages](#fixture-usages) below.
16+
See [Rename fixture](#rename-fixture) below.
17+
- **Find fixture usages** — find all usages of the fixture under the cursor across the project.
4818
Done by calling `PytrizeFixtureUsages`.
4919
Alternatively `lua require('pytrize.api').fixture_usages()`.
20+
See [Fixture usages](#fixture-usages) below.
5021

5122
## Installation
5223

53-
For example using [`packer`](https://github.com/wbthomason/packer.nvim):
54-
55-
```lua
56-
use { -- pytrize {{{
57-
'sigfriedcub1990/nvim-pytrize.lua',
58-
-- uncomment if you want to lazy load
59-
-- cmd = {'Pytrize', 'PytrizeClear', 'PytrizeJump'},
60-
-- uncomment if you want to lazy load but not use the commands
61-
-- module = 'pytrize',
62-
config = function()
63-
require("pytrize").setup({
64-
-- metrics = true, -- uncomment to log timing info for jump and rename
65-
})
66-
end,
67-
} -- }}}
68-
```
69-
7024
For example using [`lazy.nvim`](https://github.com/folke/lazy.nvim):
7125

7226
```lua
7327
{
7428
'sigfriedcub1990/nvim-pytrize.lua',
7529
version = '*',
76-
dependencies = { 'nvim-lua/plenary' },
7730
ft = 'python', -- Load only for python files
7831
opts = {
7932
-- metrics = true, -- uncomment to log timing info for jump and rename
33+
-- preferred_input = 'fzf-lua', -- uncomment to use fzf-lua for fixture usages
8034
},
8135
-- uncomment if you want to lazy load
82-
-- cmd = {'Pytrize', 'PytrizeClear', 'PytrizeJump'},
83-
} -- }}}
36+
-- cmd = {'PytrizeJumpFixture', 'PytrizeRenameFixture', 'PytrizeFixtureUsages'},
37+
}
8438
```
8539

86-
Requires [`plenary.nvim`](https://github.com/nvim-lua/plenary.nvim).
87-
8840
## Configuration
8941

9042
`require("pytrize").setup` takes an optional table of settings which currently have the default values:
@@ -94,31 +46,25 @@ Requires [`plenary.nvim`](https://github.com/nvim-lua/plenary.nvim).
9446
no_commands = false,
9547
highlight = 'LineNr',
9648
metrics = false,
97-
preferred_input = 'fzf-lua',
49+
preferred_input = nil,
9850
}
9951
```
10052

10153
where:
10254

103-
- `no_commands` can be set to `true` and the commands `Pytrize` etc won't be declared.
104-
- `highlight` defines the highlighting used for the virtual text.
55+
- `no_commands` can be set to `true` and the user commands won't be declared.
56+
- `highlight` defines the highlighting used for virtual text.
10557
- `metrics` when set to `true`, logs timing information via `vim.notify` after each jump-to-fixture and rename operation. Useful for understanding performance in large projects. The jump reports total time and index-build time; the rename reports total, grep, scoping (fixture resolution), and apply time.
10658
- `preferred_input` which method to use for displaying results (if installed). Currently `'fzf-lua'` is supported — when set, fixture usages are displayed in an [`fzf-lua`](https://github.com/ibhagwan/fzf-lua) picker instead of the quickfix list. When `nil` (the default), results go to the quickfix list.
10759

108-
## Details
109-
110-
- `pytest`s 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.
111-
Also old ids might confuse `pytrize`, but you can clear the cache with `pytest --cache-clear`.
112-
- `treesitter` is used to find the correct entry in `pytest.mark.parametrize`.
113-
11460
## Jump to fixture
11561

11662
To jump to the declaration of a fixture under the cursor, do `PytrizeJumpFixture`:
11763
![pytrize_fixture](https://user-images.githubusercontent.com/23341710/145707800-dcd49ae2-8fb1-46cc-8895-ed78ee5365b9.gif)
11864

11965
## Rename fixture
12066

121-
To rename the fixture under the cursor, do `PytrizeRenameFixture`:
67+
To rename the fixture under the cursor, do `PytrizeRenameFixture`.
12268

12369
## Fixture usages
12470

@@ -127,18 +73,6 @@ To find all usages of the fixture under the cursor, do `PytrizeFixtureUsages`.
12773
Results are loaded into Neovim's quickfix list and the quickfix window is opened automatically.
12874
Each entry shows the file, line, and the line content where the fixture is used — as a parameter, a body reference, or inside `@pytest.mark.usefixtures(...)`. The fixture definition itself is excluded from the results.
12975

130-
## Input
131-
132-
In some cases the file-path is not printed by pytest, for example when a test fails when it might look something like:
133-
134-
```
135-
136-
_________________________________ test[None2-a1-b-c1-9] _________________________________
137-
```
138-
139-
or similar.
140-
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 (via `vim.ui.select`).
141-
14276
### fzf-lua
14377

14478
When `preferred_input = 'fzf-lua'` is set and [`fzf-lua`](https://github.com/ibhagwan/fzf-lua) is installed, fixture usages (`PytrizeFixtureUsages`) are displayed in an fzf picker with a built-in previewer. Supported actions:

lua/pytrize/api.lua

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,24 @@
11
local M = {}
22

3-
--- Clear pytrize virtual text from buffer.
4-
---@param bufnr? integer Buffer number (0 or nil for current buffer)
5-
M.clear = function(bufnr)
6-
local marks = require("pytrize.marks")
7-
marks.clear(bufnr or 0)
8-
end
9-
10-
--- Set pytrize virtual text for parametrize entries in buffer.
11-
---@param bufnr? integer Buffer number (0 or nil for current buffer)
12-
M.set = function(bufnr)
13-
local cs = require("pytrize.call_spec")
14-
local marks = require("pytrize.marks")
15-
bufnr = bufnr or 0
16-
marks.clear(bufnr)
17-
local call_specs_per_func = cs.get_calls(bufnr)
18-
if call_specs_per_func == nil then
19-
return
20-
end
21-
for _, call_specs in pairs(call_specs_per_func) do
22-
for _, call_spec in ipairs(call_specs) do
23-
for _, entry_spec in ipairs(call_spec.entries) do
24-
local entry_row = entry_spec.node:start()
25-
marks.set({
26-
bufnr = bufnr,
27-
text = entry_spec.id,
28-
row = entry_row,
29-
})
30-
for _, item_spec in ipairs(entry_spec.items) do
31-
local item_row = item_spec.node:start()
32-
if item_row ~= entry_row then
33-
marks.set({
34-
bufnr = bufnr,
35-
text = item_spec.id,
36-
row = item_spec.node:start(),
37-
})
38-
end
39-
end
40-
end
41-
end
42-
end
43-
end
44-
45-
--- Jump to the parametrize entry declaration under cursor.
46-
M.jump = function()
47-
local jump = require("pytrize.jump")
48-
49-
jump.to_param_declaration()
50-
end
51-
523
--- Jump to fixture definition under cursor.
534
M.jump_fixture = function()
54-
local jump = require("pytrize.jump")
5+
local jump = require("pytrize.jump")
556

56-
jump.to_fixture_declaration()
7+
jump.to_fixture_declaration()
578
end
589

5910
--- Rename fixture under cursor across the project.
6011
M.rename_fixture = function()
61-
local rename = require("pytrize.rename")
12+
local rename = require("pytrize.rename")
6213

63-
rename.rename_fixture()
14+
rename.rename_fixture()
6415
end
6516

66-
--- Show all usages of fixture under cursor in quickfix list.
17+
--- Show all usages of fixture under cursor.
6718
M.fixture_usages = function()
68-
local usages = require("pytrize.usages")
19+
local usages = require("pytrize.usages")
6920

70-
usages.show_usages()
21+
usages.show_usages()
7122
end
7223

7324
return M

0 commit comments

Comments
 (0)