From 2cfc183029ace4dc6852f5f2b161c89f7f73bf2a Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Mon, 14 Sep 2015 07:42:23 +0200 Subject: [PATCH] monkeypatch: ensure the internal _savesyspath attribute always exists --- _pytest/monkeypatch.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/_pytest/monkeypatch.py b/_pytest/monkeypatch.py index 07998650a..6f4fcf642 100644 --- a/_pytest/monkeypatch.py +++ b/_pytest/monkeypatch.py @@ -72,6 +72,7 @@ class monkeypatch: self._setattr = [] self._setitem = [] self._cwd = None + self._savesyspath = None def setattr(self, target, name, value=notset, raising=True): """ Set attribute value on target, memorizing the old value. @@ -173,7 +174,7 @@ class monkeypatch: def syspath_prepend(self, path): """ Prepend ``path`` to ``sys.path`` list of import locations. """ - if not hasattr(self, '_savesyspath'): + if self._savesyspath is None: self._savesyspath = sys.path[:] sys.path.insert(0, str(path)) @@ -217,9 +218,9 @@ class monkeypatch: else: dictionary[name] = value self._setitem[:] = [] - if hasattr(self, '_savesyspath'): + if self._savesyspath is not None: sys.path[:] = self._savesyspath - del self._savesyspath + self._savesyspath = None if self._cwd is not None: os.chdir(self._cwd)