Merge pull request #11956 from bluetech/ruff-warning
Fix ruff deprecation warning + enable few more rules
This commit is contained in:
commit
29a5f94428
|
@ -5,7 +5,7 @@ if __name__ == "__main__":
|
||||||
import cProfile
|
import cProfile
|
||||||
import pstats
|
import pstats
|
||||||
|
|
||||||
import pytest # NOQA
|
import pytest # noqa: F401
|
||||||
|
|
||||||
script = sys.argv[1:] if len(sys.argv) > 1 else ["empty.py"]
|
script = sys.argv[1:] if len(sys.argv) > 1 else ["empty.py"]
|
||||||
cProfile.run("pytest.cmdline.main(%r)" % script, "prof")
|
cProfile.run("pytest.cmdline.main(%r)" % script, "prof")
|
||||||
|
|
|
@ -172,7 +172,7 @@ class TestRaises:
|
||||||
raise ValueError("demo error")
|
raise ValueError("demo error")
|
||||||
|
|
||||||
def test_tupleerror(self):
|
def test_tupleerror(self):
|
||||||
a, b = [1] # NOQA
|
a, b = [1] # noqa: F841
|
||||||
|
|
||||||
def test_reinterpret_fails_with_print_for_the_fun_of_it(self):
|
def test_reinterpret_fails_with_print_for_the_fun_of_it(self):
|
||||||
items = [1, 2, 3]
|
items = [1, 2, 3]
|
||||||
|
@ -180,7 +180,7 @@ class TestRaises:
|
||||||
a, b = items.pop()
|
a, b = items.pop()
|
||||||
|
|
||||||
def test_some_error(self):
|
def test_some_error(self):
|
||||||
if namenotexi: # NOQA
|
if namenotexi: # noqa: F821
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def func1(self):
|
def func1(self):
|
||||||
|
|
|
@ -87,6 +87,11 @@ target-version = ['py38']
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
src = ["src"]
|
src = ["src"]
|
||||||
line-length = 88
|
line-length = 88
|
||||||
|
|
||||||
|
[tool.ruff.format]
|
||||||
|
docstring-code-format = true
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
select = [
|
select = [
|
||||||
"B", # bugbear
|
"B", # bugbear
|
||||||
"D", # pydocstyle
|
"D", # pydocstyle
|
||||||
|
@ -97,6 +102,8 @@ select = [
|
||||||
"UP", # pyupgrade
|
"UP", # pyupgrade
|
||||||
"RUF", # ruff
|
"RUF", # ruff
|
||||||
"W", # pycodestyle
|
"W", # pycodestyle
|
||||||
|
"PIE", # flake8-pie
|
||||||
|
"PGH004", # pygrep-hooks - Use specific rule codes when using noqa
|
||||||
]
|
]
|
||||||
ignore = [
|
ignore = [
|
||||||
# bugbear ignore
|
# bugbear ignore
|
||||||
|
@ -130,9 +137,6 @@ ignore = [
|
||||||
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
|
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.ruff.format]
|
|
||||||
docstring-code-format = true
|
|
||||||
|
|
||||||
[tool.ruff.lint.pycodestyle]
|
[tool.ruff.lint.pycodestyle]
|
||||||
# In order to be able to format for 88 char in ruff format
|
# In order to be able to format for 88 char in ruff format
|
||||||
max-line-length = 120
|
max-line-length = 120
|
||||||
|
|
|
@ -452,7 +452,7 @@ class LocalPath:
|
||||||
|
|
||||||
def ensure_dir(self, *args):
|
def ensure_dir(self, *args):
|
||||||
"""Ensure the path joined with args is a directory."""
|
"""Ensure the path joined with args is a directory."""
|
||||||
return self.ensure(*args, **{"dir": True})
|
return self.ensure(*args, dir=True)
|
||||||
|
|
||||||
def bestrelpath(self, dest):
|
def bestrelpath(self, dest):
|
||||||
"""Return a string which is a relative path from self
|
"""Return a string which is a relative path from self
|
||||||
|
|
|
@ -1006,7 +1006,7 @@ class AssertionRewriter(ast.NodeVisitor):
|
||||||
if i:
|
if i:
|
||||||
fail_inner: List[ast.stmt] = []
|
fail_inner: List[ast.stmt] = []
|
||||||
# cond is set in a prior loop iteration below
|
# cond is set in a prior loop iteration below
|
||||||
self.expl_stmts.append(ast.If(cond, fail_inner, [])) # noqa
|
self.expl_stmts.append(ast.If(cond, fail_inner, [])) # noqa: F821
|
||||||
self.expl_stmts = fail_inner
|
self.expl_stmts = fail_inner
|
||||||
# Check if the left operand is a ast.NamedExpr and the value has already been visited
|
# Check if the left operand is a ast.NamedExpr and the value has already been visited
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -712,7 +712,7 @@ class TestRequestBasic:
|
||||||
)
|
)
|
||||||
def test_request_garbage(self, pytester: Pytester) -> None:
|
def test_request_garbage(self, pytester: Pytester) -> None:
|
||||||
try:
|
try:
|
||||||
import xdist # noqa
|
import xdist # noqa: F401
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -601,7 +601,7 @@ class TestAssert_reprcompare:
|
||||||
|
|
||||||
def test_list_dont_wrap_strings(self) -> None:
|
def test_list_dont_wrap_strings(self) -> None:
|
||||||
long_a = "a" * 10
|
long_a = "a" * 10
|
||||||
l1 = ["a"] + [long_a for _ in range(0, 7)]
|
l1 = ["a"] + [long_a for _ in range(7)]
|
||||||
l2 = ["should not get wrapped"]
|
l2 = ["should not get wrapped"]
|
||||||
diff = callequal(l1, l2, verbose=True)
|
diff = callequal(l1, l2, verbose=True)
|
||||||
assert diff == [
|
assert diff == [
|
||||||
|
|
|
@ -200,7 +200,7 @@ class TestAssertionRewrite:
|
||||||
assert getmsg(f2) == "assert False"
|
assert getmsg(f2) == "assert False"
|
||||||
|
|
||||||
def f3() -> None:
|
def f3() -> None:
|
||||||
assert a_global # type: ignore[name-defined] # noqa
|
assert a_global # type: ignore[name-defined] # noqa: F821
|
||||||
|
|
||||||
assert getmsg(f3, {"a_global": False}) == "assert False"
|
assert getmsg(f3, {"a_global": False}) == "assert False"
|
||||||
|
|
||||||
|
|
|
@ -535,7 +535,7 @@ class TestSession:
|
||||||
newid = item.nodeid
|
newid = item.nodeid
|
||||||
assert newid == id
|
assert newid == id
|
||||||
pprint.pprint(hookrec.calls)
|
pprint.pprint(hookrec.calls)
|
||||||
topdir = pytester.path # noqa
|
topdir = pytester.path # noqa: F841
|
||||||
hookrec.assert_contains(
|
hookrec.assert_contains(
|
||||||
[
|
[
|
||||||
("pytest_collectstart", "collector.path == topdir"),
|
("pytest_collectstart", "collector.path == topdir"),
|
||||||
|
|
|
@ -1231,8 +1231,7 @@ def test_plugin_loading_order(pytester: Pytester) -> None:
|
||||||
import myplugin
|
import myplugin
|
||||||
assert myplugin.terminal_plugin == [False, True]
|
assert myplugin.terminal_plugin == [False, True]
|
||||||
""",
|
""",
|
||||||
**{
|
myplugin="""
|
||||||
"myplugin": """
|
|
||||||
terminal_plugin = []
|
terminal_plugin = []
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
|
@ -1241,8 +1240,7 @@ def test_plugin_loading_order(pytester: Pytester) -> None:
|
||||||
def pytest_sessionstart(session):
|
def pytest_sessionstart(session):
|
||||||
config = session.config
|
config = session.config
|
||||||
terminal_plugin.append(bool(config.pluginmanager.get_plugin("terminalreporter")))
|
terminal_plugin.append(bool(config.pluginmanager.get_plugin("terminalreporter")))
|
||||||
"""
|
""",
|
||||||
},
|
|
||||||
)
|
)
|
||||||
pytester.syspathinsert()
|
pytester.syspathinsert()
|
||||||
result = pytester.runpytest("-p", "myplugin", str(p1))
|
result = pytester.runpytest("-p", "myplugin", str(p1))
|
||||||
|
|
|
@ -74,7 +74,7 @@ class TestEvaluation:
|
||||||
"""@pytest.mark.skipif("not hasattr(os, 'murks')")""",
|
"""@pytest.mark.skipif("not hasattr(os, 'murks')")""",
|
||||||
"""@pytest.mark.skipif(condition="hasattr(os, 'murks')")""",
|
"""@pytest.mark.skipif(condition="hasattr(os, 'murks')")""",
|
||||||
]
|
]
|
||||||
for i in range(0, 2):
|
for i in range(2):
|
||||||
item = pytester.getitem(
|
item = pytester.getitem(
|
||||||
f"""
|
f"""
|
||||||
import pytest
|
import pytest
|
||||||
|
|
|
@ -794,7 +794,7 @@ def test_resource_warning(pytester: Pytester, monkeypatch: pytest.MonkeyPatch) -
|
||||||
# available, using `importorskip("tracemalloc")` for example,
|
# available, using `importorskip("tracemalloc")` for example,
|
||||||
# because we want to ensure the same code path does not break in those platforms.
|
# because we want to ensure the same code path does not break in those platforms.
|
||||||
try:
|
try:
|
||||||
import tracemalloc # noqa
|
import tracemalloc # noqa: F401
|
||||||
|
|
||||||
has_tracemalloc = True
|
has_tracemalloc = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
Loading…
Reference in New Issue