Skip to main content

pytest-yapf3

Python PyTest CII Best Practices 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

Requires:

  • Python 3.6 or above
  • Pytest:
    • pytest>=5.4,<8 when pytest-yapf3<0.7
    • pytest>=7 when pytest-yapf3>=0.7

If someone use this with Python 3.5 or Pytest less than 5.4, set 'pytest-yapf3<0.6.0'.

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:

pipenv install --dev
pipenv shell

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~2022 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.

The 3 in pytest-yapf3 means this package supports Python 3 only.

Change Log

Release 0.7.0

  • Set pytest limit to >=7.
  • Fix a pytest warning with from_parent.

Release 0.6.2

  • Set pytest limit to >=5.4,<8.
  • Upgrade dependencies in Pipfile and its lock.
  • Enable GitHub actions.
  • Delete .travis.yml and .appveyor.yml

Release 0.6.1

  • Fix cache missing.

Release 0.6.0

  • Upgrade pytest to 5.4+, fix a warning.
  • Support python 3.6+ only, abandon 3.5
  • Use Pipfile with pipenv

Release 0.5.1

  • Fix coverage missing lines.
  • 100% test coverage.
  • Fix a crash when yapf crash.
  • Change development status to stable.

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

Release files for pytest-yapf3 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-yapf3 0.7.0
File Size Uploaded
pytest-yapf3-0.7.0.tar.gz 24.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-yapf3 0.7.0
File Interpreter ABI Platform
pytest_yapf3-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.4 kB

Release files / pytest-yapf3-0.7.0.tar.gz

Download URL pytest-yapf3-0.7.0.tar.gz
Size 24.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9122f31c6ff422493381fe91b391650b34bf8d9ae93b6a916724faa531ece7a9
BLAKE2b-256 checksum
How to use checksums
c3fe1a985a045f79516aad45d2be8e3e1c6e847bda475eff7971fdcf16dfc633
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / pytest_yapf3-0.7.0-py3-none-any.whl

Download URL pytest_yapf3-0.7.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1ab2b9e6ff34710749b316303a91cbf36a7d454f90c1355a1d17be7b9384bdb
BLAKE2b-256 checksum
How to use checksums
ec9a07f70d23c1b8972b7e76e09f724ffcb7c05d3511e3edb9a832a0eb939285
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page