Use temproot as a fallback if the current user couldn't be obtained
This commit is contained in:
parent
558e5406e8
commit
130e6cf8a2
|
@ -52,10 +52,14 @@ class TempdirFactory:
|
|||
basetemp.remove()
|
||||
basetemp.mkdir()
|
||||
else:
|
||||
# use a sub-directory in the temproot to speed-up
|
||||
# make_numbered_dir() call
|
||||
temproot = py.path.local.get_temproot()
|
||||
rootdir = temproot.join('pytest-of-%s' % get_user())
|
||||
user = get_user()
|
||||
if user:
|
||||
# use a sub-directory in the temproot to speed-up
|
||||
# make_numbered_dir() call
|
||||
rootdir = temproot.join('pytest-of-%s' % user)
|
||||
else:
|
||||
rootdir = temproot
|
||||
rootdir.ensure(dir=1)
|
||||
basetemp = py.path.local.make_numbered_dir(prefix='pytest-',
|
||||
rootdir=rootdir)
|
||||
|
@ -68,15 +72,14 @@ class TempdirFactory:
|
|||
|
||||
|
||||
def get_user():
|
||||
"""Return the current user name, falling back to using "tox" as user name
|
||||
because getpass relies on environment variables which might not be
|
||||
available in a tox environment (see #1010).
|
||||
"""Return the current user name, or None if getuser() does not work
|
||||
in the current environment (see #1010).
|
||||
"""
|
||||
import getpass
|
||||
try:
|
||||
return getpass.getuser()
|
||||
except ImportError:
|
||||
return 'tox'
|
||||
return None
|
||||
|
||||
# backward compatibility
|
||||
TempdirHandler = TempdirFactory
|
||||
|
|
|
@ -145,4 +145,4 @@ def test_get_user(monkeypatch):
|
|||
from _pytest.tmpdir import get_user
|
||||
monkeypatch.delenv('USER', raising=False)
|
||||
monkeypatch.delenv('USERNAME', raising=False)
|
||||
assert get_user() == 'tox'
|
||||
assert get_user() is None
|
||||
|
|
Loading…
Reference in New Issue