diff --git a/_pytest/tmpdir.py b/_pytest/tmpdir.py index a2a063200..b90e35948 100644 --- a/_pytest/tmpdir.py +++ b/_pytest/tmpdir.py @@ -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 diff --git a/testing/test_tmpdir.py b/testing/test_tmpdir.py index b04c73583..9bc0cf40a 100644 --- a/testing/test_tmpdir.py +++ b/testing/test_tmpdir.py @@ -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