Make tmpdir more resilient in case environment variables required by getpass are missing
Fix #1010
This commit is contained in:
parent
2093889ac2
commit
6676aeda5a
|
@ -56,7 +56,11 @@ class TempdirFactory:
|
|||
# make_numbered_dir() call
|
||||
import getpass
|
||||
temproot = py.path.local.get_temproot()
|
||||
rootdir = temproot.join('pytest-of-%s' % getpass.getuser())
|
||||
try:
|
||||
rootdir = temproot.join('pytest-of-%s' % getpass.getuser())
|
||||
except ImportError:
|
||||
# see issue #1010
|
||||
rootdir = temproot.join('pytest-tox')
|
||||
rootdir.ensure(dir=1)
|
||||
basetemp = py.path.local.make_numbered_dir(prefix='pytest-',
|
||||
rootdir=rootdir)
|
||||
|
|
|
@ -117,4 +117,19 @@ def test_tmpdir_factory(testdir):
|
|||
session_dir.isdir()
|
||||
""")
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(passed=1)
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
|
||||
def test_tmpdir_fallback_tox_env(testdir, monkeypatch):
|
||||
"""Test that tmpdir works even if environment variables required by getpass
|
||||
module are missing (#1010).
|
||||
"""
|
||||
monkeypatch.delenv('USER', raising=False)
|
||||
monkeypatch.delenv('USERNAME', raising=False)
|
||||
testdir.makepyfile("""
|
||||
import pytest
|
||||
def test_some(tmpdir):
|
||||
assert tmpdir.isdir()
|
||||
""")
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
|
Loading…
Reference in New Issue