Skip to content

alimasry/pytest-approve.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pytest-approve.nvim

A Neovim plugin that integrates with Python's approvaltests library. Run pytest from within Neovim and review approval mismatches in a side-by-side diff popup.

Features

  • Async pytest execution (non-blocking)
  • Side-by-side diff floating windows with scroll sync
  • Approve or reject changes with a single keypress
  • Navigate through multiple failures
  • Auto-detects approval mismatches from pytest output

Installation

Using lazy.nvim:

{
  "alimasry/pytest-approve.nvim",
  config = function()
    require("approval").setup()
  end,
  ft = "python",
}

Setup

The plugin automatically suppresses external diff tools (e.g. VS Code) by injecting a ReportQuietly reporter via a bundled pytest plugin. No conftest.py needed.

To disable this and manage the reporter yourself, set inject_reporter_plugin = false in your setup:

require("approval").setup({
  inject_reporter_plugin = false,
})

Keymaps

Key Action
<leader>tn Run nearest test
<leader>tf Run all tests in file
]a / [a Next / previous failure

Inside the diff popup:

Key Action
a Approve (rename .received.txt to .approved.txt)
q Reject / close
]a / [a Next / previous failure

Commands

  • :ApprovalRunNearest — Run the test nearest to cursor
  • :ApprovalRunFile — Run all tests in the current file
  • :ApprovalApprove — Approve the current failure
  • :ApprovalReject — Reject the current failure

Configuration

require("approval").setup({
  pytest_cmd = "pytest",                -- pytest executable
  pytest_args = { "-v", "--tb=short" }, -- default pytest arguments
  inject_reporter_plugin = true,        -- auto-suppress external diff tools
  keymaps = {
    run_nearest = "<leader>tn",
    run_file = "<leader>tf",
    next_failure = "]a",
    prev_failure = "[a",
  },
})

How It Works

  1. Open a Python test file that uses approvaltests.verify()
  2. Press <leader>tn to run the nearest test
  3. If no .approved.txt exists, the diff popup shows an empty left pane vs the received output
  4. Press a to approve — the .received.txt is renamed to .approved.txt
  5. Run the test again — it passes with a success notification
  6. If the output changes, the popup shows the diff between the old approved and new received content
  7. Press q to reject and keep the .approved.txt unchanged

Requirements

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors