Use a subdirectory in the TEMP directory to speed up tmpdir creation

Fix #105
This commit is contained in:
Bruno Oliveira 2015-07-14 18:11:30 -03:00
parent aa25fb05a9
commit 330de0a93d
3 changed files with 15 additions and 1 deletions

View File

@ -12,6 +12,12 @@
fixtures declared on the first one. fixtures declared on the first one.
Thanks Florian Bruhin for reporting and Bruno Oliveira for the PR. 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) 2.7.2 (compared to 2.7.1)
----------------------------- -----------------------------

View File

@ -43,7 +43,14 @@ class TempdirHandler:
basetemp.remove() basetemp.remove()
basetemp.mkdir() basetemp.mkdir()
else: 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._basetemp = t = basetemp.realpath()
self.trace("new basetemp", t) self.trace("new basetemp", t)
return t return t

View File

@ -8,6 +8,7 @@ envlist=
[testenv] [testenv]
commands= py.test --lsof -rfsxX {posargs:testing} commands= py.test --lsof -rfsxX {posargs:testing}
passenv = USER USERNAME
deps= deps=
nose nose
mock mock