Skip to content

Commit 6a9b406

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 54f46d7 commit 6a9b406

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/_pytest/assertion/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
from __future__ import annotations
55

6-
import os
76
from collections.abc import Generator
7+
import os
88
import sys
99
from typing import Any
1010
from typing import TYPE_CHECKING
@@ -119,6 +119,7 @@ def root_path(self):
119119
# Ref: https://github.com/pytest-dev/py/pull/207
120120
return os.path.dirname(os.path.abspath(sys.argv[0]))
121121

122+
122123
def install_importhook(config: Config) -> rewrite.AssertionRewritingHook:
123124
"""Try to install the rewrite hook, raise SystemError if it fails."""
124125
config.stash[assertstate_key] = AssertionState(config, "rewrite")

src/_pytest/assertion/rewrite.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def find_spec(
133133

134134
return importlib.util.spec_from_file_location(
135135
name,
136-
fn ,
136+
fn,
137137
loader=self,
138138
submodule_search_locations=spec.submodule_search_locations,
139139
)
@@ -251,7 +251,6 @@ def _should_rewrite(self, name: str, fn: str, state: AssertionState) -> bool:
251251

252252
return self._is_marked_for_rewrite(name, state)
253253

254-
255254
def _is_marked_for_rewrite(self, name: str, state: AssertionState) -> bool:
256255
try:
257256
return self._marked_for_rewrite_cache[name]

testing/test_assertrewrite.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,7 @@ def hook(
18821882
if PathFinder.find_spec has been called.
18831883
"""
18841884
import importlib.machinery
1885+
18851886
self.find_spec_calls: list[str] = []
18861887
self.initial_paths: set[Path] = set()
18871888

@@ -1955,7 +1956,6 @@ def test_simple_failure():
19551956
assert hook.find_spec("file") is not None
19561957
assert self.find_spec_calls == ["file"]
19571958

1958-
19591959
def test_assert_excluded_rootpath(
19601960
self, pytester: Pytester, hook: AssertionRewritingHook, monkeypatch
19611961
) -> None:
@@ -1975,21 +1975,27 @@ def test_simple_failure():
19751975
root_path = f"{os.getcwd()}/tests"
19761976

19771977
if not os.path.exists(root_path):
1978-
mkdir(root_path)
1978+
mkdir(root_path)
19791979
monkeypatch.chdir(root_path)
19801980
with mock.patch.object(hook, "fnpats", ["*.py"]):
19811981
assert hook.find_spec("file") is None
19821982

1983-
19841983
def test_assert_excluded_rewrite_for_plugins(
19851984
self, pytester: Pytester, hook: AssertionRewritingHook, monkeypatch
19861985
) -> None:
1987-
plugins= {"ayncio", "fnpats", "pytest_bdd", "django", "mock", "pytest_twisted", "trio"}
1986+
plugins = {
1987+
"ayncio",
1988+
"fnpats",
1989+
"pytest_bdd",
1990+
"django",
1991+
"mock",
1992+
"pytest_twisted",
1993+
"trio",
1994+
}
19881995
with mock.patch.object(hook, "fnpats", ["*.py"]):
19891996
for plugin in plugins:
19901997
assert hook.find_spec(plugin) is None
19911998

1992-
19931999
@pytest.mark.skipif(
19942000
sys.platform.startswith("win32"), reason="cannot remove cwd on Windows"
19952001
)

0 commit comments

Comments
 (0)