Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff
ruff is faster and handle everything we had prior. isort configuration done based on the indication from https://github.com/astral-sh/ruff/issues/4670, previousely based on reorder-python-import (#11896) flake8-docstrings was a wrapper around pydocstyle (now archived) that explicitly asks to use ruff in https://github.com/PyCQA/pydocstyle/pull/658. flake8-typing-import is useful mainly for project that support python 3.7 and the one useful check will be implemented in https://github.com/astral-sh/ruff/issues/2302 We need to keep blacken-doc because ruff does not handle detection of python code inside .md and .rst. The direct link to the repo is now used to avoid a redirection. Manual fixes: - Lines that became too long - % formatting that was not done automatically - type: ignore that were moved around - noqa of hard to fix issues (UP031 generally) - fmt: off and fmt: on that is not really identical between black and ruff - autofix re-order in pre-commit from faster to slower Co-authored-by: Ran Benita <ran@unusedvar.com>
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
# mypy: allow-untyped-defs
|
||||
import operator
|
||||
from contextlib import contextmanager
|
||||
from decimal import Decimal
|
||||
from fractions import Fraction
|
||||
from math import sqrt
|
||||
import operator
|
||||
from operator import eq
|
||||
from operator import ne
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from _pytest.pytester import Pytester
|
||||
from _pytest.python_api import _recursive_sequence_map
|
||||
import pytest
|
||||
from pytest import approx
|
||||
|
||||
|
||||
inf, nan = float("inf"), float("nan")
|
||||
|
||||
|
||||
@@ -38,9 +39,7 @@ def mocked_doctest_runner(monkeypatch):
|
||||
class MyDocTestRunner(doctest.DocTestRunner):
|
||||
def report_failure(self, out, test, example, got):
|
||||
raise AssertionError(
|
||||
"'{}' evaluates to '{}', not '{}'".format(
|
||||
example.source.strip(), got.strip(), example.want.strip()
|
||||
)
|
||||
f"'{example.source.strip()}' evaluates to '{got.strip()}', not '{example.want.strip()}'"
|
||||
)
|
||||
|
||||
return MyDocTestRunner()
|
||||
|
||||
@@ -6,7 +6,6 @@ from typing import Any
|
||||
from typing import Dict
|
||||
|
||||
import _pytest._code
|
||||
import pytest
|
||||
from _pytest.config import ExitCode
|
||||
from _pytest.main import Session
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
@@ -14,6 +13,7 @@ from _pytest.nodes import Collector
|
||||
from _pytest.pytester import Pytester
|
||||
from _pytest.python import Class
|
||||
from _pytest.python import Function
|
||||
import pytest
|
||||
|
||||
|
||||
class TestModule:
|
||||
@@ -54,13 +54,11 @@ class TestModule:
|
||||
monkeypatch.syspath_prepend(str(root1))
|
||||
p.write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
f"""\
|
||||
import x456
|
||||
def test():
|
||||
assert x456.__file__.startswith({!r})
|
||||
""".format(
|
||||
str(root2)
|
||||
)
|
||||
assert x456.__file__.startswith({str(root2)!r})
|
||||
"""
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
# mypy: allow-untyped-defs
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from _pytest.compat import getfuncargnames
|
||||
from _pytest.config import ExitCode
|
||||
from _pytest.fixtures import deduplicate_names
|
||||
@@ -13,6 +12,7 @@ from _pytest.monkeypatch import MonkeyPatch
|
||||
from _pytest.pytester import get_public_names
|
||||
from _pytest.pytester import Pytester
|
||||
from _pytest.python import Function
|
||||
import pytest
|
||||
|
||||
|
||||
def test_getfuncargnames_functions():
|
||||
@@ -1288,7 +1288,7 @@ class TestFixtureUsages:
|
||||
@pytest.mark.parametrize("scope", ["function", "session"])
|
||||
def test_parameters_without_eq_semantics(self, scope, pytester: Pytester) -> None:
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
f"""
|
||||
class NoEq1: # fails on `a == b` statement
|
||||
def __eq__(self, _):
|
||||
raise RuntimeError
|
||||
@@ -1310,9 +1310,7 @@ class TestFixtureUsages:
|
||||
|
||||
def test2(no_eq):
|
||||
pass
|
||||
""".format(
|
||||
scope=scope
|
||||
)
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest()
|
||||
result.stdout.fnmatch_lines(["*4 passed*"])
|
||||
@@ -2199,7 +2197,7 @@ class TestAutouseManagement:
|
||||
pass
|
||||
def test_check():
|
||||
assert values == ["new1", "new2", "fin2", "fin1"]
|
||||
"""
|
||||
""" # noqa: UP031 (python syntax issues)
|
||||
% locals()
|
||||
)
|
||||
reprec = pytester.inline_run("-s")
|
||||
@@ -3087,8 +3085,8 @@ class TestFixtureMarker:
|
||||
pass
|
||||
def test_other():
|
||||
pass
|
||||
"""
|
||||
% {"scope": scope}
|
||||
""" # noqa: UP031 (python syntax issues)
|
||||
% {"scope": scope} # noqa: UP031 (python syntax issues)
|
||||
)
|
||||
reprec = pytester.inline_run("-lvs")
|
||||
reprec.assertoutcome(passed=3)
|
||||
@@ -3287,7 +3285,7 @@ class TestRequestScopeAccess:
|
||||
assert request.config
|
||||
def test_func():
|
||||
pass
|
||||
"""
|
||||
""" # noqa: UP031 (python syntax issues)
|
||||
% (scope, ok.split(), error.split())
|
||||
)
|
||||
reprec = pytester.inline_run("-l")
|
||||
@@ -3308,7 +3306,7 @@ class TestRequestScopeAccess:
|
||||
assert request.config
|
||||
def test_func(arg):
|
||||
pass
|
||||
"""
|
||||
""" # noqa: UP031 (python syntax issues)
|
||||
% (scope, ok.split(), error.split())
|
||||
)
|
||||
reprec = pytester.inline_run()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# mypy: allow-untyped-defs
|
||||
import pytest
|
||||
from _pytest._code import getfslineno
|
||||
from _pytest.fixtures import getfixturemarker
|
||||
from _pytest.pytester import Pytester
|
||||
from _pytest.python import Function
|
||||
import pytest
|
||||
|
||||
|
||||
def test_wrapped_getfslineno() -> None:
|
||||
|
||||
@@ -14,7 +14,6 @@ from typing import Sequence
|
||||
from typing import Tuple
|
||||
from typing import Union
|
||||
|
||||
import pytest
|
||||
from _pytest import fixtures
|
||||
from _pytest import python
|
||||
from _pytest.compat import getfuncargnames
|
||||
@@ -24,6 +23,8 @@ from _pytest.pytester import Pytester
|
||||
from _pytest.python import Function
|
||||
from _pytest.python import IdMaker
|
||||
from _pytest.scope import Scope
|
||||
import pytest
|
||||
|
||||
|
||||
# import hypothesis
|
||||
# from hypothesis import strategies
|
||||
@@ -1941,7 +1942,7 @@ class TestMarkersWithParametrization:
|
||||
|
||||
@pytest.mark.parametrize("strict", [True, False])
|
||||
def test_xfail_passing_is_xpass(self, pytester: Pytester, strict: bool) -> None:
|
||||
s = """
|
||||
s = f"""
|
||||
import pytest
|
||||
|
||||
m = pytest.mark.xfail("sys.version_info > (0, 0, 0)", reason="some bug", strict={strict})
|
||||
@@ -1953,9 +1954,7 @@ class TestMarkersWithParametrization:
|
||||
])
|
||||
def test_increment(n, expected):
|
||||
assert n + 1 == expected
|
||||
""".format(
|
||||
strict=strict
|
||||
)
|
||||
"""
|
||||
pytester.makepyfile(s)
|
||||
reprec = pytester.inline_run()
|
||||
passed, failed = (2, 1) if strict else (3, 0)
|
||||
@@ -2006,7 +2005,7 @@ class TestMarkersWithParametrization:
|
||||
|
||||
@pytest.mark.parametrize("strict", [True, False])
|
||||
def test_parametrize_marked_value(self, pytester: Pytester, strict: bool) -> None:
|
||||
s = """
|
||||
s = f"""
|
||||
import pytest
|
||||
|
||||
@pytest.mark.parametrize(("n", "expected"), [
|
||||
@@ -2021,9 +2020,7 @@ class TestMarkersWithParametrization:
|
||||
])
|
||||
def test_increment(n, expected):
|
||||
assert n + 1 == expected
|
||||
""".format(
|
||||
strict=strict
|
||||
)
|
||||
"""
|
||||
pytester.makepyfile(s)
|
||||
reprec = pytester.inline_run()
|
||||
passed, failed = (0, 2) if strict else (2, 0)
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from _pytest.outcomes import Failed
|
||||
from _pytest.pytester import Pytester
|
||||
import pytest
|
||||
|
||||
|
||||
class TestRaises:
|
||||
|
||||
Reference in New Issue
Block a user