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.
pip install pytest-yapf3Requires:
- Python 3.6 or above
- Pytest:
pytest>=5.4,<8whenpytest-yapf3<0.7pytest>=7whenpytest-yapf3>=0.7
If someone use this with Python 3.5 or Pytest less than 5.4, set 'pytest-yapf3<0.6.0'.
Modify setup.cfg (or pytest.ini):
[tool:pytest]
addopts =
--yapf
--yapfdiff
yapf-ignore =
setup.py
src/package/auto_generated/**.pyAdd --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:cacheproviderThis may crash if any other pytest plugin not supports.rm -rf .pytest_cache/v/yapfThis is ugly, but safe for any environment.
- Basic support to validate
yapf. - Fix the diff line count error and improve the performance.
- Display
YAPF-checkas the error session name. - Display
YAPFinpytest --verbose. - Add
yapfas a marker to enablepytest -m yapf. - Support
yapf-ignoreto ignore specified files. - Skip running if a file is not changed.
- 100% test coverage.
Prepare the environment:
pipenv install --dev
pipenv shellRun test:
pytestLike black, if your project always pass yapf checking provided by this project, you can use an unofficial badge to show off.
[](https://github.com/google/yapf).. image:: https://img.shields.io/badge/code%20style-yapf-blue
:target: https://github.com/google/yapf
:alt: Code style: yapfThe MIT License (MIT)
Copyright (c) 2019~2023 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.