Skip to main content

Validate your Python file format with yapf

Project description

pytest-yapf3

Travis AppVeyor codecov Code style: yapf

Validate your Python file format with yapf.

This is a pytest plugin, which make sure your python file is exactly formatted by yapf, or it will crash when running pytest.

Install

Version Python Format Status Download MIT

pip install pytest-yapf3

Usage

Modify setup.cfg (or pytest.ini):

[tool:pytest]
addopts =
    --yapf
    --yapfdiff
yapf-ignore =
    setup.py
    src/package/auto_generated/**.py

Add --yapf to pytest configuration addopts. If run with pytest -m yapf, only yapf is checked.

By default, only line summaries is displayed. With an optional --yapfdiff, a full text of yapf -d is displayed. If not configured here, pytest --yapfdiff will also work.

An optional yapf-ignore is supported. Each line specifies a glob pattern of files which should not check yapf.

The pytest will cache success results of pytest-yapf3, and will not check again if files not changed. Sometimes you may want to disable it. There are 2 ways:

  • pytest -p no:cacheprovider This may crash if any other pytest plugin not supports.
  • rm -rf .pytest_cache/v/yapf This is ugly, but safe for any environment.

Features and Todos

  • Basic support to validate yapf.
  • Fix the diff line count error and improve the performance.
  • Display YAPF-check as the error session name.
  • Display YAPF in pytest --verbose.
  • Add yapf as a marker to enable pytest -m yapf.
  • Support yapf-ignore to ignore specified files.
  • Skip running if a file is not changed.
  • 100% test coverage.

Develop

Prepare the environment:

source your/virtual/env
pip install -e .[dev]

Run test:

pytest

Badge

Like black, if your project always pass yapf checking provided by this project, you can use an unofficial badge to show off.

Markdown (README.md)

[![Code style: yapf](https://img.shields.io/badge/code%20style-yapf-blue)](https://github.com/google/yapf)

reStructuredText (README.rst)

.. image:: https://img.shields.io/badge/code%20style-yapf-blue
    :target: https://github.com/google/yapf
    :alt: Code style: yapf

License

The MIT License (MIT)

Copyright (c) 2019 Yan QiDong

This repository is forked from pytest-yapf in 2019, which is not maintained since 2017. Besides extra features, the project structure is adjusted, and the code is enhanced to pass linters like flake8, pylint and, of course, yapf.

Change Log

Release 0.5.0

  • Skip running if a file is not changed.
  • Add more usage description in README.

Release 0.4.0

  • Add yapf as a pytest marker to enable pytest -m yapf
  • Support yapf-ignore to ignore specified files
  • Fix a probabilistic issue caused by \r

Release 0.3.0

  • Display YAPF-check as the error session name
  • Display ::YAPF in pytest --verbose

Release 0.2.0

Since forked from pytest-yapf 0.1.1, there are some improvements:

  • Restructure the project and rewrite documents
  • Support Python 3.4+ only
  • Add linters to pytest, and fix their errors
  • Fix the line count error
  • Change build configurations in Travis and AppVeyor
  • Support coverage and displayed in codecov

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

pytest-yapf3-0.5.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

pytest_yapf3-0.5.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest-yapf3-0.5.0.tar.gz.

File metadata

  • Download URL: pytest-yapf3-0.5.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.0 CPython/3.7.1

File hashes

Hashes for pytest-yapf3-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e959e9aebb3279bbc0afe620fe59e1376ad296e704af974f7fc213619cfbacd5
MD5 0a2de0df11a0b086d6b69764da9c0e21
BLAKE2b-256 931015296e2251f7443ddb95200d3533b7f959303988ad846d1b083eb6232298

See more details on using hashes here.

File details

Details for the file pytest_yapf3-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_yapf3-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.0 CPython/3.7.1

File hashes

Hashes for pytest_yapf3-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6829bdfa8aa5980df0246fe7adca28e631c7d956eecd7cef286381aba77bd80f
MD5 ef47b7a0196178ab42422bfff59b328e
BLAKE2b-256 de752c2c72e144229b35662af1be42967efa3d4767a75055c8b1bbf013dab375

See more details on using hashes here.

Supported by

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