[ruff] Add ruff's check and autofix existing issues
This commit is contained in:
@@ -17,7 +17,7 @@ import pytest
|
||||
def ignore_encoding_warning():
|
||||
with warnings.catch_warnings():
|
||||
with contextlib.suppress(NameError): # new in 3.10
|
||||
warnings.simplefilter("ignore", EncodingWarning) # type: ignore [name-defined] # noqa: F821
|
||||
warnings.simplefilter("ignore", EncodingWarning) # type: ignore [name-defined]
|
||||
yield
|
||||
|
||||
|
||||
|
||||
@@ -1032,7 +1032,7 @@ def test_log_set_path(pytester: Pytester) -> None:
|
||||
def pytest_runtest_setup(item):
|
||||
config = item.config
|
||||
logging_plugin = config.pluginmanager.get_plugin("logging-plugin")
|
||||
report_file = os.path.join({repr(report_dir_base)}, item._request.node.name)
|
||||
report_file = os.path.join({report_dir_base!r}, item._request.node.name)
|
||||
logging_plugin.set_log_path(report_file)
|
||||
return (yield)
|
||||
"""
|
||||
|
||||
@@ -3086,7 +3086,7 @@ class TestFixtureMarker:
|
||||
def test_other():
|
||||
pass
|
||||
""" # noqa: UP031 (python syntax issues)
|
||||
% {"scope": scope} # noqa: UP031 (python syntax issues)
|
||||
% {"scope": scope}
|
||||
)
|
||||
reprec = pytester.inline_run("-lvs")
|
||||
reprec.assertoutcome(passed=3)
|
||||
|
||||
@@ -147,7 +147,7 @@ class TestRaises:
|
||||
try:
|
||||
pytest.raises(ValueError, int, "0")
|
||||
except pytest.fail.Exception as e:
|
||||
assert e.msg == f"DID NOT RAISE {repr(ValueError)}"
|
||||
assert e.msg == f"DID NOT RAISE {ValueError!r}"
|
||||
else:
|
||||
assert False, "Expected pytest.raises.Exception"
|
||||
|
||||
@@ -155,7 +155,7 @@ class TestRaises:
|
||||
with pytest.raises(ValueError):
|
||||
pass
|
||||
except pytest.fail.Exception as e:
|
||||
assert e.msg == f"DID NOT RAISE {repr(ValueError)}"
|
||||
assert e.msg == f"DID NOT RAISE {ValueError!r}"
|
||||
else:
|
||||
assert False, "Expected pytest.raises.Exception"
|
||||
|
||||
|
||||
@@ -914,16 +914,16 @@ class TestAssert_reprcompare:
|
||||
assert expl == [
|
||||
r"'hyv\xe4' == 'hyva\u0308'",
|
||||
"",
|
||||
f"- {str(right)}",
|
||||
f"+ {str(left)}",
|
||||
f"- {right!s}",
|
||||
f"+ {left!s}",
|
||||
]
|
||||
|
||||
expl = callequal(left, right, verbose=2)
|
||||
assert expl == [
|
||||
r"'hyv\xe4' == 'hyva\u0308'",
|
||||
"",
|
||||
f"- {str(right)}",
|
||||
f"+ {str(left)}",
|
||||
f"- {right!s}",
|
||||
f"+ {left!s}",
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -190,7 +190,7 @@ class TestDoctests:
|
||||
)
|
||||
doctest = f"""
|
||||
>>> "{test_string}"
|
||||
{repr(test_string)}
|
||||
{test_string!r}
|
||||
"""
|
||||
fn = pytester.path / "test_encoding.txt"
|
||||
fn.write_text(doctest, encoding=encoding)
|
||||
|
||||
@@ -227,7 +227,7 @@ class TestInlineRunModulesCleanup:
|
||||
|
||||
def spy_factory(self):
|
||||
class SysModulesSnapshotSpy:
|
||||
instances: List["SysModulesSnapshotSpy"] = [] # noqa: F821
|
||||
instances: List["SysModulesSnapshotSpy"] = []
|
||||
|
||||
def __init__(self, preserve=None) -> None:
|
||||
SysModulesSnapshotSpy.instances.append(self)
|
||||
@@ -725,7 +725,7 @@ def test_run_result_repr() -> None:
|
||||
# known exit code
|
||||
r = pytester_mod.RunResult(1, outlines, errlines, duration=0.5)
|
||||
assert repr(r) == (
|
||||
f"<RunResult ret={str(pytest.ExitCode.TESTS_FAILED)} len(stdout.lines)=3"
|
||||
f"<RunResult ret={pytest.ExitCode.TESTS_FAILED!s} len(stdout.lines)=3"
|
||||
" len(stderr.lines)=4 duration=0.50s>"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user