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

preview_player
Показать описание
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.

repos:
rev: v2.4.0
hooks:
- id: flake8
args: ["--config", ".flake8"]
- repo: local
hooks:
- id: run-tests
language: script
name: Run tests
stages: [commit]

#!/bin/bash
~/Documents/code/blogthedata/django_project/venv/bin/python3 -m pytest django_project/tests
Рекомендации по теме
Комментарии
Автор

your explaining is so much clear to me. keep it up

hashnoxt
Автор

There is an error in the video. Instead of passing in the .flake8 config file with config_file, you should do it this way:
hooks:
- id: flake8
args: ["--config", ".flake8"]

See the description for the correct config code.

johnsolly