Configuring Pre-Commit Hooks to Automate Python Testing and Linting in vscode (Visual Studio Code)

Опубликовано: 12 Апрель 2026
на канале: John Solly
6,376
46

In this video tutorial, I'll show you how to set up pre-commit hooks to automatically run Python tests and linting checks every time you commit code changes. Pre-commit hooks are an easy and efficient way to ensure that your code is always up to standards and free of errors, saving you time and effort in the long run. I'll walk you through the process of installing and configuring pre-commit and the necessary plugins, as well as demonstrate how to customize the hook to fit your specific needs. By the end of this tutorial, you'll have a fully functional pre-commit hook setup that will save you time and effort in the development process.

pre-commit-config.yaml
repos:
repo: https://github.com/pre-commit/pre-com...
rev: v2.4.0
hooks:
id: flake8
args: ["--config", ".flake8"]
repo: local
hooks:
id: run-tests
language: script
name: Run tests
entry: ./run_tests.sh
stages: [commit]

run_tests.sh
#!/bin/bash
~/Documents/code/blogthedata/django_project/venv/bin/python3 -m pytest django_project/tests