Skip to content

Commit

Permalink
fixup! fix _should_rewrite: pass py.path.local
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Dec 23, 2020
1 parent ec3aeb7 commit 9fd867d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,24 @@ def _early_rewrite_bailout(self, name, state):
state.trace("early skip of rewriting module: {}".format(name))
return True

def _should_rewrite(self, name: str, fn: str, state: "AssertionState") -> bool:
def _should_rewrite(self, name: str, path: "py.path.local", state: "AssertionState") -> bool:
# always rewrite conftest files
if os.path.basename(fn) == "conftest.py":
state.trace("rewriting conftest file: {!r}".format(fn))
if path.basename == "conftest.py":
state.trace("rewriting conftest file: {}".format(path))
return True

if self.session is not None:
if self.session.isinitpath(py.path.local(fn)):
if self.session.isinitpath(path):
state.trace(
"matched test file (was specified on cmdline): {!r}".format(fn)
"matched test file (was specified on cmdline): {}".format(path)
)
return True

# modules not passed explicitly on the command line are only
# rewritten if they match the naming convention for test files
fn_path = PurePath(fn)
for pat in self.fnpats:
if fnmatch_ex(pat, fn_path):
state.trace("matched test file {!r}".format(fn))
if fnmatch_ex(pat, path):
state.trace("matched test file {}".format(path))
return True

return self._is_marked_for_rewrite(name, state)
Expand Down

0 comments on commit 9fd867d

Please sign in to comment.