Skip to content

Migrate formatting and linting to Ruff #675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,18 @@ repos:
- id: rstcheck
additional_dependencies:
- tomli==2.0.1
- repo: https://github.com/asottile/pyupgrade
rev: ce40a160603ab0e7d9c627ae33d7ef3906e2d2b2 # frozen: v3.19.1
hooks:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: a4920527036bb9a3f3e6055d595849d67d0da066 # frozen: 25.1.0
hooks:
- id: black
- repo: https://github.com/adamchainz/blacken-docs
rev: 78a9dcbecf4f755f65d1f3dec556bc249d723600 # frozen: 1.19.1
hooks:
- id: blacken-docs
additional_dependencies:
- black==25.1.0
- repo: https://github.com/pycqa/isort
rev: c8ab4a5b21bac924d106e3103dd7c979fdd0f9bc # frozen: 6.0.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 12753357c00c3fb8615100354c9fdc6ab80b044d # frozen: v0.11.10
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/PyCQA/flake8
rev: 4b5e89b4b108a6c1a000c591d334a99a80d34c7b # frozen: 7.2.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-logging
- flake8-tidy-imports
- id: ruff-check
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: f40886d54c729f533f864ed6ce584e920feb0af7 # frozen: v1.15.0
hooks:
Expand Down
40 changes: 35 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,42 @@ test = [
"pytest-xdist",
]

[tool.isort]
add_imports = [
"from __future__ import annotations",
[tool.ruff]
lint.select = [
# flake8-bugbear
"B",
# flake8-comprehensions
"C4",
# pycodestyle
"E",
# Pyflakes errors
"F",
# isort
"I",
# flake8-simplify
"SIM",
# flake8-tidy-imports
"TID",
# pyupgrade
"UP",
# Pyflakes warnings
"W",
]
force_single_line = true
profile = "black"
lint.ignore = [
# flake8-bugbear opinionated rules
"B9",
# line-too-long
"E501",
# suppressible-exception
"SIM105",
# if-else-block-instead-of-if-exp
"SIM108",
]
lint.extend-safe-fixes = [
# non-pep585-annotation
"UP006",
]
lint.isort.required-imports = [ "from __future__ import annotations" ]

[tool.pyproject-fmt]
max_supported_python = "3.13"
Expand Down
14 changes: 5 additions & 9 deletions src/pytest_randomly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
import sys
from itertools import groupby
from types import ModuleType
from typing import Any
from typing import Callable
from typing import TypeVar
from typing import Any, Callable, TypeVar

from _pytest.config import Config
from _pytest.config.argparsing import Parser
from _pytest.nodes import Item
from pytest import Collector
from pytest import fixture
from pytest import hookimpl
from pytest import Collector, fixture, hookimpl

if sys.version_info < (3, 10):
from importlib_metadata import entry_points
Expand Down Expand Up @@ -117,9 +113,9 @@ def pytest_configure(config: Config) -> None:

seed_value = config.getoption("randomly_seed")
if seed_value == "last":
assert hasattr(
config, "cache"
), "The cacheprovider plugin is required to use 'last'"
assert hasattr(config, "cache"), (
"The cacheprovider plugin is required to use 'last'"
)
assert config.cache is not None
seed = config.cache.get("randomly_seed", default_seed)
elif seed_value == "default":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pytest_randomly.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def test_failing_import(testdir):

modcol = testdir.getmodulecol("pytest_plugins='xasdlkj',")
with pytest.raises(ImportError):
modcol.obj
modcol.obj # noqa: B018


def test_entrypoint_injection(pytester, monkeypatch):
Expand Down
4 changes: 0 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@ commands =
-m pytest -p no:randomly {posargs:tests}
dependency_groups =
test

[flake8]
max-line-length = 88
extend-ignore = E203,E501