Skip to content

Commit 1592f85

Browse files
committed
13403: Disable assertion rewriting for external modules - refactor
1 parent 54f46d7 commit 1592f85

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/_pytest/assertion/rewrite.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,13 @@ def _early_rewrite_bailout(self, name: str, state: AssertionState) -> bool:
218218
if fnmatch_ex(pat, path):
219219
return False
220220

221-
if not path.is_relative_to(state.root_path):
222-
return True
223221

224222
if self._is_marked_for_rewrite(name, state):
225223
return False
226224

225+
if not path.is_relative_to(state.root_path):
226+
return True
227+
227228
state.trace(f"early skip of rewriting module: {name}")
228229
return True
229230

@@ -241,11 +242,9 @@ def _should_rewrite(self, name: str, fn: str, state: AssertionState) -> bool:
241242
# modules not passed explicitly on the command line are only
242243
# rewritten if they match the naming convention for test files
243244
fn_path = PurePath(fn)
244-
if not fn_path.is_relative_to(state.root_path):
245-
return False
246245

247246
for pat in self.fnpats:
248-
if fnmatch_ex(pat, fn_path):
247+
if fnmatch_ex(pat, fn_path) and fn_path.is_relative_to(state.root_path):
249248
state.trace(f"matched test file {fn!r}")
250249
return True
251250

0 commit comments

Comments
 (0)