From 59e7d2bbc9f6b29734fc744664a58beec65c6ccb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Feb 2023 19:30:33 -0300 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#10712) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/psf/black: 22.12.0 → 23.1.0](https://github.com/psf/black/compare/22.12.0...23.1.0) - [github.com/PyCQA/autoflake: v2.0.0 → v2.0.1](https://github.com/PyCQA/autoflake/compare/v2.0.0...v2.0.1) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update .pre-commit-config.yaml * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bruno Oliveira --- .pre-commit-config.yaml | 6 +++--- doc/en/how-to/fixtures.rst | 1 - doc/en/how-to/monkeypatch.rst | 9 +++------ doc/en/how-to/writing_hook_functions.rst | 1 + src/_pytest/assertion/rewrite.py | 1 - src/_pytest/config/__init__.py | 2 -- src/_pytest/config/compat.py | 1 - src/_pytest/doctest.py | 1 - src/_pytest/outcomes.py | 1 - src/_pytest/python.py | 3 ++- src/_pytest/reports.py | 1 - testing/acceptance_test.py | 1 - testing/test_cacheprovider.py | 1 - testing/test_doctest.py | 2 -- testing/test_junitxml.py | 2 -- testing/test_runner.py | 1 + 16 files changed, 10 insertions(+), 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2a92f89b3..2adcc4d49 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ default_language_version: python: "3.10" repos: - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.1.0 hooks: - id: black args: [--safe, --quiet] @@ -10,7 +10,7 @@ repos: rev: 1.13.0 hooks: - id: blacken-docs - additional_dependencies: [black==22.12.0] + additional_dependencies: [black==23.1.0] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: @@ -23,7 +23,7 @@ repos: exclude: _pytest/(debugging|hookspec).py language_version: python3 - repo: https://github.com/PyCQA/autoflake - rev: v2.0.0 + rev: v2.0.1 hooks: - id: autoflake name: autoflake diff --git a/doc/en/how-to/fixtures.rst b/doc/en/how-to/fixtures.rst index 3acf39d0f..d8517c2c8 100644 --- a/doc/en/how-to/fixtures.rst +++ b/doc/en/how-to/fixtures.rst @@ -1237,7 +1237,6 @@ If the data created by the factory requires managing, the fixture can take care @pytest.fixture def make_customer_record(): - created_records = [] def _make_customer_record(name): diff --git a/doc/en/how-to/monkeypatch.rst b/doc/en/how-to/monkeypatch.rst index 81edd00bd..a9504dcb3 100644 --- a/doc/en/how-to/monkeypatch.rst +++ b/doc/en/how-to/monkeypatch.rst @@ -135,10 +135,10 @@ This can be done in our test file by defining a class to represent ``r``. # this is the previous code block example import app + # custom class to be the mock return value # will override the requests.Response returned from requests.get class MockResponse: - # mock json() method always returns a specific testing dictionary @staticmethod def json(): @@ -146,7 +146,6 @@ This can be done in our test file by defining a class to represent ``r``. def test_get_json(monkeypatch): - # Any arguments may be passed and mock_get() will always return our # mocked object, which only has the .json() method. def mock_get(*args, **kwargs): @@ -181,6 +180,7 @@ This mock can be shared across tests using a ``fixture``: # app.py that includes the get_json() function import app + # custom class to be the mock return value of requests.get() class MockResponse: @staticmethod @@ -358,7 +358,6 @@ For testing purposes we can patch the ``DEFAULT_CONFIG`` dictionary to specific def test_connection(monkeypatch): - # Patch the values of DEFAULT_CONFIG to specific # testing values only for this test. monkeypatch.setitem(app.DEFAULT_CONFIG, "user", "test_user") @@ -383,7 +382,6 @@ You can use the :py:meth:`monkeypatch.delitem ` to remove v def test_missing_user(monkeypatch): - # patch the DEFAULT_CONFIG t be missing the 'user' key monkeypatch.delitem(app.DEFAULT_CONFIG, "user", raising=False) @@ -404,6 +402,7 @@ separate fixtures for each potential mock and reference them in the needed tests # app.py with the connection string function import app + # all of the mocks are moved into separated fixtures @pytest.fixture def mock_test_user(monkeypatch): @@ -425,7 +424,6 @@ separate fixtures for each potential mock and reference them in the needed tests # tests reference only the fixture mocks that are needed def test_connection(mock_test_user, mock_test_database): - expected = "User Id=test_user; Location=test_db;" result = app.create_connection_string() @@ -433,7 +431,6 @@ separate fixtures for each potential mock and reference them in the needed tests def test_missing_user(mock_missing_default_user): - with pytest.raises(KeyError): _ = app.create_connection_string() diff --git a/doc/en/how-to/writing_hook_functions.rst b/doc/en/how-to/writing_hook_functions.rst index da2961c97..71379016f 100644 --- a/doc/en/how-to/writing_hook_functions.rst +++ b/doc/en/how-to/writing_hook_functions.rst @@ -249,6 +249,7 @@ and use pytest_addoption as follows: # contents of hooks.py + # Use firstresult=True because we only want one plugin to define this # default value @hookspec(firstresult=True) diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index e2648029c..42664add4 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -274,7 +274,6 @@ class AssertionRewritingHook(importlib.abc.MetaPathFinder, importlib.abc.Loader) return f.read() if sys.version_info >= (3, 10): - if sys.version_info >= (3, 12): from importlib.resources.abc import TraversableResources else: diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index b4dbc0da4..720f39531 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -62,7 +62,6 @@ from _pytest.warning_types import PytestConfigWarning from _pytest.warning_types import warn_explicit_for if TYPE_CHECKING: - from _pytest._code.code import _TracebackStyle from _pytest.terminal import TerminalReporter from .argparsing import Argument @@ -1067,7 +1066,6 @@ class Config: try: self.parse(args) except UsageError: - # Handle --version and --help here in a minimal fashion. # This gets done via helpconfig normally, but its # pytest_cmdline_main is not called in case of errors. diff --git a/src/_pytest/config/compat.py b/src/_pytest/config/compat.py index ba267d215..5bd922a4a 100644 --- a/src/_pytest/config/compat.py +++ b/src/_pytest/config/compat.py @@ -43,7 +43,6 @@ class PathAwareHookProxy: @_wraps(hook) def fixed_hook(**kw): - path_value: Optional[Path] = kw.pop(path_var, None) fspath_value: Optional[LEGACY_PATH] = kw.pop(fspath_var, None) if fspath_value is not None: diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index 771f0890d..455ad62cc 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -531,7 +531,6 @@ class DoctestModule(Module): if _is_mocked(obj): return with _patch_unwrap_mock_aware(): - # Type ignored because this is a private function. super()._find( # type:ignore[misc] tests, obj, name, module, source_lines, globs, seen diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py index e46b663dd..2a998e421 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -219,7 +219,6 @@ def _resolve_msg_to_reason( """ __tracebackhide__ = True if msg is not None: - if reason: from pytest import UsageError diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 62c31b0f4..d04b6fa4d 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -789,7 +789,8 @@ def _call_with_optional_argument(func, arg) -> None: def _get_first_non_fixture_func(obj: object, names: Iterable[str]) -> Optional[object]: """Return the attribute from the given object to be used as a setup/teardown - xunit-style function, but only if not marked as a fixture to avoid calling it twice.""" + xunit-style function, but only if not marked as a fixture to avoid calling it twice. + """ for name in names: meth: Optional[object] = getattr(obj, name, None) if meth is not None and fixtures.getfixturemarker(meth) is None: diff --git a/src/_pytest/reports.py b/src/_pytest/reports.py index 1b2821c71..b49dfb32a 100644 --- a/src/_pytest/reports.py +++ b/src/_pytest/reports.py @@ -572,7 +572,6 @@ def _report_kwargs_from_json(reportdict: Dict[str, Any]) -> Dict[str, Any]: and "reprcrash" in reportdict["longrepr"] and "reprtraceback" in reportdict["longrepr"] ): - reprtraceback = deserialize_repr_traceback( reportdict["longrepr"]["reprtraceback"] ) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 46352e130..62acf1209 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -871,7 +871,6 @@ class TestDurations: ) def test_calls_show_2(self, pytester: Pytester, mock_timing) -> None: - pytester.makepyfile(self.source) result = pytester.runpytest_inprocess("--durations=2") assert result.ret == 0 diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py index c381a8448..2f8517f99 100644 --- a/testing/test_cacheprovider.py +++ b/testing/test_cacheprovider.py @@ -494,7 +494,6 @@ class TestLastFailed: def test_lastfailed_collectfailure( self, pytester: Pytester, monkeypatch: MonkeyPatch ) -> None: - pytester.makepyfile( test_maybe=""" import os diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 2f73feb8c..d2944fa2b 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -1236,7 +1236,6 @@ class TestDoctestSkips: class TestDoctestAutoUseFixtures: - SCOPES = ["module", "session", "class", "function"] def test_doctest_module_session_fixture(self, pytester: Pytester): @@ -1379,7 +1378,6 @@ class TestDoctestAutoUseFixtures: class TestDoctestNamespaceFixture: - SCOPES = ["module", "session", "class", "function"] @pytest.mark.parametrize("scope", SCOPES) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index b266c76d9..90804c619 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -253,7 +253,6 @@ class TestPython: duration_report: str, run_and_parse: RunAndParse, ) -> None: - # mock LogXML.node_reporter so it always sets a known duration to each test report object original_node_reporter = LogXML.node_reporter @@ -603,7 +602,6 @@ class TestPython: node.assert_attr(failures=3, tests=3) for index, char in enumerate("<&'"): - tnode = node.find_nth_by_tag("testcase", index) tnode.assert_attr( classname="test_failure_escape", name="test_func[%s]" % char diff --git a/testing/test_runner.py b/testing/test_runner.py index 49adc04fe..c6d5b8aaf 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -906,6 +906,7 @@ def test_makereport_getsource_dynamic_code( def test_store_except_info_on_error() -> None: """Test that upon test failure, the exception info is stored on sys.last_traceback and friends.""" + # Simulate item that might raise a specific exception, depending on `raise_error` class var class ItemMightRaise: nodeid = "item_that_raises"