Skip to content
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
7 changes: 2 additions & 5 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ def _fix(node, lineno, col_offset):
return node


@functools.lru_cache(maxsize=1)
def _get_assertion_exprs(src: bytes) -> Dict[int, str]:
"""Return a mapping from {lineno: "assertion test expression"}."""
ret: Dict[int, str] = {}
Expand Down Expand Up @@ -675,10 +676,6 @@ def __init__(
self.enable_assertion_pass_hook = False
self.source = source

@functools.lru_cache(maxsize=1)
def _assert_expr_to_lineno(self) -> Dict[int, str]:
return _get_assertion_exprs(self.source)

def run(self, mod: ast.Module) -> None:
"""Find all assert statements in *mod* and rewrite them."""
if not mod.body:
Expand Down Expand Up @@ -906,7 +903,7 @@ def visit_Assert(self, assert_: ast.Assert) -> List[ast.stmt]:

# Passed
fmt_pass = self.helper("_format_explanation", msg)
orig = self._assert_expr_to_lineno()[assert_.lineno]
orig = _get_assertion_exprs(self.source)[assert_.lineno]
hook_call_pass = ast.Expr(
self.helper(
"_call_assertion_pass",
Expand Down
10 changes: 8 additions & 2 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ def _try_load_conftest(
if x.is_dir():
self._getconftestmodules(x, importmode, rootpath)

@lru_cache(maxsize=128)
def _getconftestmodules(
self, path: Path, importmode: Union[str, ImportMode], rootpath: Path
) -> List[types.ModuleType]:
Expand All @@ -534,12 +533,19 @@ def _getconftestmodules(
else:
directory = path

# Optimization: avoid repeated searches in the same directory.
# Assumes always called with same importmode and rootpath.
existing_clist = self._dirpath2confmods.get(directory)
if existing_clist:
return existing_clist

# XXX these days we may rather want to use config.rootpath
# and allow users to opt into looking into the rootdir parent
# directories instead of requiring to specify confcutdir.
clist = []
confcutdir_parents = self._confcutdir.parents if self._confcutdir else []
for parent in reversed((directory, *directory.parents)):
if self._confcutdir and parent in self._confcutdir.parents:
if parent in confcutdir_parents:
continue
conftestpath = parent / "conftest.py"
if conftestpath.is_file():
Expand Down