Skip to content

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 Neovim
  • neotest-python — a plugin for Pytest support
  • nvim-nio — required by neotest, runs in the background
  • Terminal — sometimes I run tests manually with a command

What does my workflow look like?

  1. I open the project in Neovim: bash nvim .

  2. I go to the test file: :Telescope find_files → pick the file

  3. I run the test under the cursor: vim :lua require("neotest").run.run()

  4. I run all tests in the file: vim :lua require("neotest").run.run(vim.fn.expand("%"))

  5. 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.ini and pytest-cov
  • Collecting test results into reports

Neovim doesn't run my tests for me. But it lets me test on my own terms.

— Andrzej 🐢