From 52fba25ff94f01e510ff5e7f52da5bb74a32669e Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Fri, 2 Feb 2024 21:13:43 +0100 Subject: [PATCH] [flake8-bugbear] Fix all the useless expressions that are justified --- pyproject.toml | 1 - scripts/update-plugin-list.py | 2 +- src/_pytest/unittest.py | 4 ++-- testing/_py/test_local.py | 4 ++-- testing/code/test_excinfo.py | 12 ++++++------ testing/test_compat.py | 4 ++-- testing/test_legacypath.py | 2 +- testing/test_mark.py | 2 +- 8 files changed, 15 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bda2091a3..7adb20467 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -148,7 +148,6 @@ ignore = [ "B011", # Do not `assert False` (`python -O` removes these calls) "B015", # Pointless comparison. Did you mean to assign a value? "B017", # `pytest.raises(Exception)` should be considered evil - "B018", # Found useless expression. "B023", # Function definition does not bind loop variable `warning` "B028", # No explicit `stacklevel` keyword argument found # pycodestyle ignore diff --git a/scripts/update-plugin-list.py b/scripts/update-plugin-list.py index 7c5ac9277..2c57414c0 100644 --- a/scripts/update-plugin-list.py +++ b/scripts/update-plugin-list.py @@ -208,7 +208,7 @@ def main() -> None: f.write(f"This list contains {len(plugins)} plugins.\n\n") f.write(".. only:: not latex\n\n") - wcwidth # reference library that must exist for tabulate to work + _ = wcwidth # reference library that must exist for tabulate to work plugin_table = tabulate.tabulate(plugins, headers="keys", tablefmt="rst") f.write(indent(plugin_table, " ")) f.write("\n\n") diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py index 29a53ad5c..eccd7eca6 100644 --- a/src/_pytest/unittest.py +++ b/src/_pytest/unittest.py @@ -209,8 +209,8 @@ class TestCaseFunction(Function): ) # Invoke the attributes to trigger storing the traceback # trial causes some issue there. - excinfo.value - excinfo.traceback + _ = excinfo.value + _ = excinfo.traceback except TypeError: try: try: diff --git a/testing/_py/test_local.py b/testing/_py/test_local.py index 11519c7c1..0c8575c4e 100644 --- a/testing/_py/test_local.py +++ b/testing/_py/test_local.py @@ -1241,9 +1241,9 @@ class TestWINLocalPath: def test_owner_group_not_implemented(self, path1): with pytest.raises(NotImplementedError): - path1.stat().owner + _ = path1.stat().owner with pytest.raises(NotImplementedError): - path1.stat().group + _ = path1.stat().group def test_chmod_simple_int(self, path1): mode = path1.stat().mode diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index a0ee28d48..cce23bf87 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -387,7 +387,7 @@ def test_excinfo_no_python_sourcecode(tmp_path: Path) -> None: excinfo = pytest.raises(ValueError, template.render, h=h) for item in excinfo.traceback: print(item) # XXX: for some reason jinja.Template.render is printed in full - item.source # shouldn't fail + _ = item.source # shouldn't fail if isinstance(item.path, Path) and item.path.name == "test.txt": assert str(item.source) == "{{ h()}}:" @@ -418,7 +418,7 @@ def test_codepath_Queue_example() -> None: def test_match_succeeds(): with pytest.raises(ZeroDivisionError) as excinfo: - 0 // 0 + _ = 0 // 0 excinfo.match(r".*zero.*") @@ -584,7 +584,7 @@ class TestFormattedExcinfo: try: def f(): - 1 / 0 + _ = 1 / 0 f() @@ -601,7 +601,7 @@ class TestFormattedExcinfo: print(line) assert lines == [ " def f():", - "> 1 / 0", + "> _ = 1 / 0", "E ZeroDivisionError: division by zero", ] @@ -638,7 +638,7 @@ raise ValueError() pr = FormattedExcinfo() try: - 1 / 0 + _ = 1 / 0 except ZeroDivisionError: excinfo = ExceptionInfo.from_current() @@ -1582,7 +1582,7 @@ def test_no_recursion_index_on_recursion_error(): return getattr(self, "_" + attr) with pytest.raises(RuntimeError) as excinfo: - RecursionDepthError().trigger + _ = RecursionDepthError().trigger assert "maximum recursion" in str(excinfo.getrepr()) diff --git a/testing/test_compat.py b/testing/test_compat.py index 4ea905354..9e66e9eca 100644 --- a/testing/test_compat.py +++ b/testing/test_compat.py @@ -170,9 +170,9 @@ class ErrorsHelper: def test_helper_failures() -> None: helper = ErrorsHelper() with pytest.raises(Exception): - helper.raise_exception + _ = helper.raise_exception with pytest.raises(OutcomeException): - helper.raise_fail_outcome + _ = helper.raise_fail_outcome def test_safe_getattr() -> None: diff --git a/testing/test_legacypath.py b/testing/test_legacypath.py index 6b933a6d9..850f14c58 100644 --- a/testing/test_legacypath.py +++ b/testing/test_legacypath.py @@ -108,7 +108,7 @@ class TestFixtureRequestSessionScoped: AttributeError, match="path not available in session-scoped context", ): - session_request.fspath + _ = session_request.fspath @pytest.mark.parametrize("config_type", ["ini", "pyproject"]) diff --git a/testing/test_mark.py b/testing/test_mark.py index 4604baafd..6e183a178 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -42,7 +42,7 @@ class TestMark: def test_pytest_mark_name_starts_with_underscore(self) -> None: mark = MarkGenerator(_ispytest=True) with pytest.raises(AttributeError): - mark._some_name + _ = mark._some_name def test_marked_class_run_twice(pytester: Pytester) -> None: