Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/pytrize/jump/fixture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ M.to_declaration = function()
end

open_file(location.file)
vim.api.nvim_win_set_cursor(0, {location.linenr, 0})
vim.api.nvim_win_set_cursor(0, {location.linenr, location.col})

if require('pytrize.settings').settings.metrics then
local total = hrtime() - t0
Expand Down
3 changes: 2 additions & 1 deletion lua/pytrize/ts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ M.scan_fixtures = function(filepath)

local fixtures = {}
for _, def in ipairs(defs) do
local row = def.name_node:start()
local row, col = def.func_node:start()
fixtures[def.name] = {
file = filepath,
linenr = row + 1,
col = col,
}
end

Expand Down
28 changes: 28 additions & 0 deletions tests/pytrize/ts_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,34 @@ describe("scan_fixtures", function()
os.remove(path)
end)

it("returns col=0 for a top-level fixture", function()
local path = write_tmp_py("scan_col_top", {
"import pytest",
"",
"@pytest.fixture",
"def db():",
" return 'connection'",
})
local fixtures = ts_utils.scan_fixtures(path)
assert.are.equal(0, fixtures.db.col)
os.remove(path)
end)

it("returns correct col for a fixture defined inside a class", function()
local path = write_tmp_py("scan_col_class", {
"import pytest",
"",
"class TestFixtures:",
" @pytest.fixture",
" def class_fix(self):",
" return 42",
})
local fixtures = ts_utils.scan_fixtures(path)
assert.are.equal(5, fixtures.class_fix.linenr)
assert.are.equal(4, fixtures.class_fix.col)
os.remove(path)
end)

it("cleans up buffer for files that were not previously loaded", function()
local path = write_tmp_py("scan4", {
"import pytest",
Expand Down