Testing with neotest

Testing with neotest

neotest turns the editor into the test runner. With the pytest adapter (or your language’s equivalent), verdicts render exactly where the tests live.

The keymaps

Grouped under <leader>t in the course config:

KeysAction
<leader>tarun the entire suite
<leader>tfrun the current file
<leader>ttrun the nearest test
<leader>tstoggle the summary panel

The loop that changes habits

Open a test file and press <leader>ta. After the run, every test function carries its verdict in the gutter — green check or red cross, right next to the def. The summary panel (<leader>ts) shows the whole suite as a living tree: passes, failures, timings, staying in sync as you work.

When a test fails: fix the code (or the expectation), :w, and rerun just that file with <leader>tf. Watching the gutter flip from red to green without ever leaving the buffer is the moment the terminal round trip dies.

Why it sticks

Cost is the whole story. When rerunning the suite is one keystroke and the result lands next to the code, you run tests constantly — which is exactly the habit every testing book tries to teach. The tooling makes the discipline free.