Testing in Neovim — how I run Pytest without leaving the editor¶
In traditional IDEs, we click the "Run" button, pick a file, and wait for the terminal to open... In Neovim, I wanted to do this faster, calmer, and without the mouse.
My testing tools¶
neotest— a framework for running tests from inside Neovimneotest-python— a plugin for Pytest supportnvim-nio— required byneotest, runs in the background- Terminal — sometimes I run tests manually with a command
What does my workflow look like?¶
-
I open the project in Neovim:
bash nvim . -
I go to the test file:
:Telescope find_files→ pick the file -
I run the test under the cursor:
vim :lua require("neotest").run.run() -
I run all tests in the file:
vim :lua require("neotest").run.run(vim.fn.expand("%")) -
I check the test result in a separate window or in the quickfix list
What else did I add?¶
- Keyboard shortcuts (for example,
nnoremap <leader>t :lua require("neotest").run.run()<CR>) - Automatic test detection in the
tests/folder - Highlighting for tests that failed
What does this give me?¶
- I don't need to switch between the editor and the terminal
- I get fast feedback without too much noise
- I can run exactly the tests I care about
What else do I want to add?¶
- Automatically running tests on save
- Integration with
pytest.iniandpytest-cov - Collecting test results into reports
Neovim doesn't run my tests for me. But it lets me test on my own terms.
— Andrzej 🐢