test/.pre-commit-config.yaml
Andrew Vaillancourt 66bc9b9fc5 Enable pre-push unit test check via pre-commit
Adds a new pre-push hook to .pre-commit-config.yaml that runs
`pytest unit_tests/` before allowing any push, including `git review`.

This ensures that regressions in fast-running unit tests are caught
before changes are submitted for review.

To activate the hook locally:
  pre-commit install --hook-type pre-commit
  pre-commit install --hook-type pre-push

Change-Id: Ia2d0fe56eabf6466e27f0432ac2fb91c7b444832
Signed-off-by: Andrew Vaillancourt <andrew.vaillancourt@windriver.com>
2025-05-08 00:34:20 -04:00

82 lines
2.7 KiB
YAML

# -----------------------------------------------------------------------------
# Pre-Commit Hook Configuration for starlingx/test
#
# This configuration ensures code quality by enforcing formatting, style, and
# documentation standards before commits. The following tools are used:
#
# - `isort` → Sorts and organizes imports.
# - `black` → Formats Python code to maintain consistent style.
# - `flake8` → Runs linting checks for Python code style and errors.
# - `pydocstyle` → Enforces PEP 257 and Google-style docstring conventions.
# - `pydoclint` → Validates that docstrings match function signatures.
# - `interrogate` → Ensures all public functions and classes have docstrings.
#
# Notes:
# - `interrogate` is configured to ignore nested functions (`--ignore-nested-functions`)
# to avoid unnecessary enforcement on pytest teardowns and small helper functions.
# - `black` uses `pyproject.toml` for consistency across formatting tools.
# - `pydocstyle` and `pydoclint` ensure compliance with Google-style docstrings.
# -----------------------------------------------------------------------------
default_stages: [pre-commit]
default_language_version:
python: python3.11
repos:
- repo: local
hooks:
- id: isort
name: isort - import sorting
entry: isort
language: python
types: [python]
args: [--settings-path, pyproject.toml]
- id: black
name: black - fail if formatting needed
entry: black
language: python
types: [python]
args: [--config, pyproject.toml, --check]
- id: black
name: black - auto-format code
entry: black
language: python
types: [python]
args: [--config, pyproject.toml]
- id: flake8
name: flake8 - code lint and style checks
entry: flake8
language: python
types: [python]
args: [--config=.flake8]
- id: pydocstyle
name: pydocstyle - enforce PEP 257 and Google-style docstrings
entry: pydocstyle
language: python
types: [python]
args: [--config=pydocstyle.ini]
- id: pydoclint
name: pydoclint - enforce Google-style docstring structure
entry: pydoclint
language: python
types: [python]
args: [--config=pyproject.toml]
- id: interrogate
name: interrogate - ensure all functions and classes have docstrings
entry: interrogate
language: python
types: [python]
args: ["--fail-under", "100", "--ignore-module", "--ignore-init-method", "--ignore-nested-functions", "--verbose"]
- id: unit-tests
name: Run unit tests before push
entry: bash -c 'pytest unit_tests/'
language: system
pass_filenames: false
stages: [push]