Created
October 24, 2023 18:01
-
-
Save nicoddemus/b7f8d756abe33738450ea28e561fc9ae to your computer and use it in GitHub Desktop.
Trying out ruff formatter on pytest - 7 files modifed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py | |
index 0288d7a54..54d5956d4 100644 | |
--- a/src/_pytest/_code/code.py | |
+++ b/src/_pytest/_code/code.py | |
@@ -486,9 +486,7 @@ class ExceptionInfo(Generic[E]): | |
.. versionadded:: 7.4 | |
""" | |
- assert ( | |
- exception.__traceback__ | |
- ), "Exceptions passed to ExcInfo.from_exception(...) must have a non-None __traceback__." | |
+ assert exception.__traceback__, "Exceptions passed to ExcInfo.from_exception(...) must have a non-None __traceback__." | |
exc_info = (type(exception), exception, exception.__traceback__) | |
return cls.from_exc_info(exc_info, exprinfo) | |
diff --git a/src/_pytest/_py/path.py b/src/_pytest/_py/path.py | |
index 24348525a..e09f69d06 100644 | |
--- a/src/_pytest/_py/path.py | |
+++ b/src/_pytest/_py/path.py | |
@@ -760,7 +760,10 @@ class LocalPath: | |
# expected "Callable[[str, Any, Any], TextIOWrapper]" [arg-type] | |
# Which seems incorrect, given io.open supports the given argument types. | |
return error.checked_call( | |
- io.open, self.strpath, mode, encoding=encoding # type:ignore[arg-type] | |
+ io.open, | |
+ self.strpath, | |
+ mode, | |
+ encoding=encoding, # type:ignore[arg-type] | |
) | |
return error.checked_call(open, self.strpath, mode) | |
@@ -1277,7 +1280,8 @@ class LocalPath: | |
# error: Argument 1 has incompatible type overloaded function; expected "Callable[[str], str]" [arg-type] | |
# Which seems incorrect, given tempfile.mkdtemp supports the given argument types. | |
path = error.checked_call( | |
- tempfile.mkdtemp, dir=str(rootdir) # type:ignore[arg-type] | |
+ tempfile.mkdtemp, | |
+ dir=str(rootdir), # type:ignore[arg-type] | |
) | |
return cls(path) | |
diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py | |
index 258ed9f9a..dde3954cb 100644 | |
--- a/src/_pytest/assertion/rewrite.py | |
+++ b/src/_pytest/assertion/rewrite.py | |
@@ -1013,9 +1013,7 @@ class AssertionRewriter(ast.NodeVisitor): | |
] | |
): | |
pytest_temp = self.variable() | |
- self.variables_overwrite[self.scope][ | |
- v.left.target.id | |
- ] = v.left # type:ignore[assignment] | |
+ self.variables_overwrite[self.scope][v.left.target.id] = v.left # type:ignore[assignment] | |
v.left.target.id = pytest_temp | |
self.push_format_context() | |
res, expl = self.visit(v) | |
@@ -1059,9 +1057,7 @@ class AssertionRewriter(ast.NodeVisitor): | |
if isinstance(arg, ast.Name) and arg.id in self.variables_overwrite.get( | |
self.scope, {} | |
): | |
- arg = self.variables_overwrite[self.scope][ | |
- arg.id | |
- ] # type:ignore[assignment] | |
+ arg = self.variables_overwrite[self.scope][arg.id] # type:ignore[assignment] | |
res, expl = self.visit(arg) | |
arg_expls.append(expl) | |
new_args.append(res) | |
@@ -1069,9 +1065,7 @@ class AssertionRewriter(ast.NodeVisitor): | |
if isinstance( | |
keyword.value, ast.Name | |
) and keyword.value.id in self.variables_overwrite.get(self.scope, {}): | |
- keyword.value = self.variables_overwrite[self.scope][ | |
- keyword.value.id | |
- ] # type:ignore[assignment] | |
+ keyword.value = self.variables_overwrite[self.scope][keyword.value.id] # type:ignore[assignment] | |
res, expl = self.visit(keyword.value) | |
new_kwargs.append(ast.keyword(keyword.arg, res)) | |
if keyword.arg: | |
@@ -1108,13 +1102,9 @@ class AssertionRewriter(ast.NodeVisitor): | |
if isinstance( | |
comp.left, ast.Name | |
) and comp.left.id in self.variables_overwrite.get(self.scope, {}): | |
- comp.left = self.variables_overwrite[self.scope][ | |
- comp.left.id | |
- ] # type:ignore[assignment] | |
+ comp.left = self.variables_overwrite[self.scope][comp.left.id] # type:ignore[assignment] | |
if isinstance(comp.left, ast.NamedExpr): | |
- self.variables_overwrite[self.scope][ | |
- comp.left.target.id | |
- ] = comp.left # type:ignore[assignment] | |
+ self.variables_overwrite[self.scope][comp.left.target.id] = comp.left # type:ignore[assignment] | |
left_res, left_expl = self.visit(comp.left) | |
if isinstance(comp.left, (ast.Compare, ast.BoolOp)): | |
left_expl = f"({left_expl})" | |
@@ -1132,9 +1122,7 @@ class AssertionRewriter(ast.NodeVisitor): | |
and next_operand.target.id == left_res.id | |
): | |
next_operand.target.id = self.variable() | |
- self.variables_overwrite[self.scope][ | |
- left_res.id | |
- ] = next_operand # type:ignore[assignment] | |
+ self.variables_overwrite[self.scope][left_res.id] = next_operand # type:ignore[assignment] | |
next_res, next_expl = self.visit(next_operand) | |
if isinstance(next_operand, (ast.Compare, ast.BoolOp)): | |
next_expl = f"({next_expl})" | |
diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py | |
index d56274629..93cff6abf 100644 | |
--- a/src/_pytest/fixtures.py | |
+++ b/src/_pytest/fixtures.py | |
@@ -1120,7 +1120,8 @@ def resolve_fixture_function( | |
# Handle the case where fixture is defined not in a test class, but some other class | |
# (for example a plugin class with a fixture), see #2270. | |
if hasattr(fixturefunc, "__self__") and not isinstance( | |
- request.instance, fixturefunc.__self__.__class__ # type: ignore[union-attr] | |
+ request.instance, | |
+ fixturefunc.__self__.__class__, # type: ignore[union-attr] | |
): | |
return fixturefunc | |
fixturefunc = getimfunc(fixturedef.func) | |
diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py | |
index 99d33954d..76ed00762 100644 | |
--- a/src/_pytest/pytester.py | |
+++ b/src/_pytest/pytester.py | |
@@ -1428,8 +1428,9 @@ class Pytester: | |
__tracebackhide__ = True | |
timeout_message = ( | |
- "{seconds} second timeout expired running:" | |
- " {command}".format(seconds=timeout, command=cmdargs) | |
+ "{seconds} second timeout expired running:" " {command}".format( | |
+ seconds=timeout, command=cmdargs | |
+ ) | |
) | |
popen.kill() | |
diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py | |
index 34845cec1..b5783c878 100644 | |
--- a/src/_pytest/unittest.py | |
+++ b/src/_pytest/unittest.py | |
@@ -217,7 +217,9 @@ class TestCaseFunction(Function): | |
# Unwrap potential exception info (see twisted trial support below). | |
rawexcinfo = getattr(rawexcinfo, "_rawexcinfo", rawexcinfo) | |
try: | |
- excinfo = _pytest._code.ExceptionInfo[BaseException].from_exc_info(rawexcinfo) # type: ignore[arg-type] | |
+ excinfo = _pytest._code.ExceptionInfo[BaseException].from_exc_info( | |
+ rawexcinfo | |
+ ) # type: ignore[arg-type] | |
# Invoke the attributes to trigger storing the traceback | |
# trial causes some issue there. | |
excinfo.value | |
@@ -362,9 +364,7 @@ def pytest_runtest_makereport(item: Item, call: CallInfo[None]) -> None: | |
# handled internally, and doesn't reach here. | |
unittest = sys.modules.get("unittest") | |
if ( | |
- unittest | |
- and call.excinfo | |
- and isinstance(call.excinfo.value, unittest.SkipTest) # type: ignore[attr-defined] | |
+ unittest and call.excinfo and isinstance(call.excinfo.value, unittest.SkipTest) # type: ignore[attr-defined] | |
): | |
excinfo = call.excinfo | |
call2 = CallInfo[None].from_call( |
Author
nicoddemus
commented
Oct 24, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment