From 330de0a93db404921c7a4c80305b43fd87bc3119 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 14 Jul 2015 18:11:30 -0300 Subject: [PATCH] Use a subdirectory in the TEMP directory to speed up tmpdir creation Fix #105 --- CHANGELOG | 6 ++++++ _pytest/tmpdir.py | 9 ++++++++- tox.ini | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index d9fa3a4f0..8b6feb3a2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,12 @@ fixtures declared on the first one. Thanks Florian Bruhin for reporting and Bruno Oliveira for the PR. +- optimized tmpdir fixture initialization, which should make test sessions + faster (specially when using pytest-xdist). The only visible effect + is that now pytest uses a subdirectory in the $TEMP directory for all + directories created by this fixture (defaults to $TEMP/pytest-$USER). + Thanks Bruno Oliveira for the PR. + 2.7.2 (compared to 2.7.1) ----------------------------- diff --git a/_pytest/tmpdir.py b/_pytest/tmpdir.py index 53c396b76..5e83ec931 100644 --- a/_pytest/tmpdir.py +++ b/_pytest/tmpdir.py @@ -43,7 +43,14 @@ class TempdirHandler: basetemp.remove() basetemp.mkdir() else: - basetemp = py.path.local.make_numbered_dir(prefix='pytest-') + # use a sub-directory in the temproot to speed-up + # make_numbered_dir() call + import getpass + temproot = py.path.local.get_temproot() + rootdir = temproot.join('pytest-%s' % getpass.getuser()) + rootdir.ensure(dir=1) + basetemp = py.path.local.make_numbered_dir(prefix='pytest-', + rootdir=rootdir) self._basetemp = t = basetemp.realpath() self.trace("new basetemp", t) return t diff --git a/tox.ini b/tox.ini index f5528bb17..2e1a15b8b 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,7 @@ envlist= [testenv] commands= py.test --lsof -rfsxX {posargs:testing} +passenv = USER USERNAME deps= nose mock