From 97d8e9fbecc3a2f496522928e24f75889a3d1544 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 28 May 2019 18:25:45 +0200 Subject: [PATCH] minor: getbasetemp: dedent, improve assert --- src/_pytest/tmpdir.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index f1b16fb5c..a8a703771 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -60,29 +60,29 @@ class TempPathFactory(object): def getbasetemp(self): """ return base temporary directory. """ - if self._basetemp is None: - if self._given_basetemp is not None: - basetemp = self._given_basetemp - ensure_reset_dir(basetemp) - basetemp = basetemp.resolve() - else: - from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT") - temproot = Path(from_env or tempfile.gettempdir()).resolve() - user = get_user() or "unknown" - # use a sub-directory in the temproot to speed-up - # make_numbered_dir() call - rootdir = temproot.joinpath("pytest-of-{}".format(user)) - rootdir.mkdir(exist_ok=True) - basetemp = make_numbered_dir_with_cleanup( - prefix="pytest-", root=rootdir, keep=3, lock_timeout=LOCK_TIMEOUT - ) - assert basetemp is not None - self._basetemp = t = basetemp - self._trace("new basetemp", t) - return t - else: + if self._basetemp is not None: return self._basetemp + if self._given_basetemp is not None: + basetemp = self._given_basetemp + ensure_reset_dir(basetemp) + basetemp = basetemp.resolve() + else: + from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT") + temproot = Path(from_env or tempfile.gettempdir()).resolve() + user = get_user() or "unknown" + # use a sub-directory in the temproot to speed-up + # make_numbered_dir() call + rootdir = temproot.joinpath("pytest-of-{}".format(user)) + rootdir.mkdir(exist_ok=True) + basetemp = make_numbered_dir_with_cleanup( + prefix="pytest-", root=rootdir, keep=3, lock_timeout=LOCK_TIMEOUT + ) + assert basetemp is not None, basetemp + self._basetemp = t = basetemp + self._trace("new basetemp", t) + return t + @attr.s class TempdirFactory(object):