Skip to main content

Run pytest on the test at cursor and update inline snapshots.

Project description

vscode-pytest-update-snapshot

Run pytest on the test under your cursor and update inline snapshots (VSCode-friendly).

Install / Run (no install with uvx)

uvx vscode-pytest-update-snapshot tests/test_example.py 12
# ensure it uses your project venv interpreter:
uvx --python ".venv/Scripts/python.exe" vscode-pytest-update-snapshot tests/test_example.py 12

Pass extra pytest args after --:

uvx vscode-pytest-update-snapshot tests/test_example.py 12 -- -q -k "mycase"

Requirements

  • Python 3.10+ (tested on 3.12)
  • uv installed on your PATH (pipx install uv or pip install uvtools—use your preferred method)
  • A project virtual environment selected in VSCode (bottom-right status bar → Select Interpreter)
  • These packages installed in your project venv:
    • pytest
    • inline-snapshot (with Ruff formatting, see config below)
    • ruff

Install with uv:

uv add pytest ruff inline-snapshot --dev

Inline-snapshot formatting via Ruff

Add this to your pyproject.toml:

[tool.inline-snapshot]
# Format with Ruff; read/write via stdin/stdout so inline-snapshot can capture it
format-command = "ruff format --stdin-filename {filename}"

[tool.ruff]
line-length = 100
target-version = "py312"

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
docstring-code-format = true

[tool.pytest.ini_options]
addopts = "-q"
testpaths = ["tests"]

VSCode setup

This repo includes templates for a handy “Update snapshot (test at cursor)” action.

Keybinding

  1. Open Command PalettePreferences: Open Keyboard Shortcuts (JSON).
  2. Copy the contents of template_keybindings.json into the file and save.

VSCode’s keybindings file supports comments (JSONC). You can keep the comments.

Task

  1. For a workspace task: open .vscode/tasks.json (create if missing) and copy from template_tasks.json.
  2. For a profile-level (user) task: Command PaletteTasks: Open User Tasks, then paste the task there.

Either way, VSCode tasks also support comments (JSONC).

Run it

  • Put the cursor on a test line in a Python file.
  • Press the configured shortcut (default Ctrl+Alt+U) or run Terminal → Run Task → Update snapshot (test at cursor).
  • Make sure your interpreter/venv is selected in the VSCode status bar so pytest and inline-snapshot are found.

Install this CLI (editable during development)

uv pip install -e .

(or publish and use uvx, but for local dev the editable install is simplest.)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vscode_pytest_update_snapshot-0.2.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file vscode_pytest_update_snapshot-0.2.0.tar.gz.

File metadata

File hashes

Hashes for vscode_pytest_update_snapshot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 151de3a39f070f177d76ceaa30d5b8995838a52102759210f7e82460160fce25
MD5 74c39af19b92e5cdfae00c342e0ade61
BLAKE2b-256 6d1e2da4b11f500d39d62aa6f0888c015a51ac4135de241cc390177f888f4334

See more details on using hashes here.

File details

Details for the file vscode_pytest_update_snapshot-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vscode_pytest_update_snapshot-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3c2de5fe09ee372fd9814001df1ef65d6dd0a3546b9b82b61689b9c0d62e453
MD5 7a101bdc1b570c9d279c6b31d9632ed4
BLAKE2b-256 cae34f61290ce2febf15fd0e244b61ab71166139905defcf764331292b8a86ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page