Skip to content

Commit abd69ac

Browse files
committed
13403: Disable assertion rewriting for external modules - fix ruff
1 parent c947f9a commit abd69ac

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

src/_pytest/assertion/__init__.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,17 @@
33

44
from __future__ import annotations
55

6-
from collections.abc import Generator
7-
import os
86
import sys
9-
from typing import Any
7+
from collections.abc import Generator
8+
from typing import Any, TYPE_CHECKING
109
from typing import Protocol
11-
from typing import TYPE_CHECKING
1210

13-
from _pytest.assertion import rewrite
14-
from _pytest.assertion import truncate
15-
from _pytest.assertion import util
11+
from _pytest.assertion import rewrite, truncate, util
1612
from _pytest.assertion.rewrite import assertstate_key
17-
from _pytest.config import Config
18-
from _pytest.config import hookimpl
13+
from _pytest.config import Config, hookimpl
1914
from _pytest.config.argparsing import Parser
2015
from _pytest.nodes import Item
2116

22-
2317
if TYPE_CHECKING:
2418
from _pytest.main import Session
2519

src/_pytest/assertion/rewrite.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ def _should_rewrite(self, name: str, fn: str, state: AssertionState) -> bool:
238238
# modules not passed explicitly on the command line are only
239239
# rewritten if they match the naming convention for test files
240240
fn_path = PurePath(fn)
241-
242241
for pat in self.fnpats:
243242
if fnmatch_ex(pat, fn_path) and fn_path.is_relative_to(state.rootpath):
244243
state.trace(f"matched test file {fn!r}")

testing/test_assertrewrite.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,9 +1298,7 @@ def test_meta_path():
12981298
assert pytester.runpytest().ret == 0
12991299

13001300
def test_rootpath_base(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
1301-
"""
1302-
Base cases for get rootpath from AssertionState
1303-
"""
1301+
"""Base cases for get rootpath from AssertionState"""
13041302
from _pytest.assertion import AssertionState
13051303

13061304
config = pytester.parseconfig()
@@ -2007,9 +2005,7 @@ def test_simple_failure():
20072005
def test_assert_rewrites_only_rootpath(
20082006
self, pytester: Pytester, hook: AssertionRewritingHook, monkeypatch
20092007
) -> None:
2010-
"""
2011-
If test files contained outside the rootpath, then skip them
2012-
"""
2008+
"""If test files contained outside the rootpath, then skip them"""
20132009
pytester.makepyfile(
20142010
**{
20152011
"file.py": """\
@@ -2039,9 +2035,7 @@ def test_simple_failure():
20392035
def test_assert_rewrite_correct_for_conftfest(
20402036
self, pytester: Pytester, hook: AssertionRewritingHook, monkeypatch
20412037
) -> None:
2042-
"""
2043-
Conftest is always rewritten regardless of the root dir
2044-
"""
2038+
"""Conftest is always rewritten regardless of the root dir"""
20452039
pytester.makeconftest(
20462040
"""
20472041
import pytest

0 commit comments

Comments
 (0)