Skip to content

[pre-commit.ci] pre-commit autoupdate #10712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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]
- repo: https://github.com/asottile/blacken-docs
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:
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion doc/en/how-to/fixtures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 3 additions & 6 deletions doc/en/how-to/monkeypatch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,17 @@ 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():
return {"mock_key": "mock_response"}


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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -383,7 +382,6 @@ You can use the :py:meth:`monkeypatch.delitem <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)

Expand All @@ -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):
Expand All @@ -425,15 +424,13 @@ 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()
assert result == expected


def test_missing_user(mock_missing_default_user):

with pytest.raises(KeyError):
_ = app.create_connection_string()

Expand Down
1 change: 1 addition & 0 deletions doc/en/how-to/writing_hook_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ def get_data(self, pathname: Union[str, bytes]) -> bytes:
return f.read()

if sys.version_info >= (3, 10):

if sys.version_info >= (3, 12):
from importlib.resources.abc import TraversableResources
else:
Expand Down
2 changes: 0 additions & 2 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
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
Expand Down Expand Up @@ -1067,7 +1066,6 @@ def pytest_cmdline_parse(
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.
Expand Down
1 change: 0 additions & 1 deletion src/_pytest/config/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def __getattr__(self, key, _wraps=functools.wraps):

@_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:
Expand Down
1 change: 0 additions & 1 deletion src/_pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ def _find(
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
Expand Down
1 change: 0 additions & 1 deletion src/_pytest/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ def _resolve_msg_to_reason(
"""
__tracebackhide__ = True
if msg is not None:

if reason:
from pytest import UsageError

Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion src/_pytest/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ def deserialize_repr_crash(repr_crash_dict: Optional[Dict[str, Any]]):
and "reprcrash" in reportdict["longrepr"]
and "reprtraceback" in reportdict["longrepr"]
):

reprtraceback = deserialize_repr_traceback(
reportdict["longrepr"]["reprtraceback"]
)
Expand Down
1 change: 0 additions & 1 deletion testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,6 @@ def test_calls(self, pytester: Pytester, mock_timing) -> None:
)

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
Expand Down
1 change: 0 additions & 1 deletion testing/test_cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ def test_a2(): pass
def test_lastfailed_collectfailure(
self, pytester: Pytester, monkeypatch: MonkeyPatch
) -> None:

pytester.makepyfile(
test_maybe="""
import os
Expand Down
2 changes: 0 additions & 2 deletions testing/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,6 @@ def my_config_context():


class TestDoctestAutoUseFixtures:

SCOPES = ["module", "session", "class", "function"]

def test_doctest_module_session_fixture(self, pytester: Pytester):
Expand Down Expand Up @@ -1379,7 +1378,6 @@ def auto(request):


class TestDoctestNamespaceFixture:

SCOPES = ["module", "session", "class", "function"]

@pytest.mark.parametrize("scope", SCOPES)
Expand Down
2 changes: 0 additions & 2 deletions testing/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ def test_junit_duration_report(
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

Expand Down Expand Up @@ -603,7 +602,6 @@ def test_func(arg1):
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
Expand Down
1 change: 1 addition & 0 deletions testing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ def test_fix(foo):
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"
Expand Down