From 1f50de268d6c9bbd271cc9643ea309bfa8383415 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 24 Oct 2018 14:04:51 +0200 Subject: [PATCH] _getconftestmodules: avoid isfile()/dirpath() Ref: https://github.com/pytest-dev/pytest/issues/2206#issuecomment-432623646 --- src/_pytest/config/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index c7bde99799b..d663733c565 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -388,13 +388,13 @@ def _getconftestmodules(self, path): if self._noconftest: return [] - if path.isfile(): - directory = path.dirpath() - else: - directory = path try: - return self._path2confmods[directory] + return self._path2confmods[path] except KeyError: + if path.isfile(): + directory = path.dirpath() + else: + directory = path # XXX these days we may rather want to use config.rootdir # and allow users to opt into looking into the rootdir parent # directories instead of requiring to specify confcutdir @@ -407,7 +407,7 @@ def _getconftestmodules(self, path): mod = self._importconftest(conftestpath) clist.append(mod) - self._path2confmods[directory] = clist + self._path2confmods[path] = clist return clist def _rget_with_confmod(self, name, path):