diff options
author | Florian Bruhin <me@the-compiler.org> | 2015-07-25 12:11:42 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2015-07-25 12:11:42 +0200 |
commit | 137daab49798a5f85ca2801ffc4358a25622b08e (patch) | |
tree | 81d98c53b6659957b5ebd88604864495c66a0d74 /pylint | |
parent | 67a771316cebe75152d83d657b9b68820537c2d3 (diff) | |
download | pylint-git-137daab49798a5f85ca2801ffc4358a25622b08e.tar.gz |
Fix tests when $HOME is unset in the environment.
tox beginning with v2.0 does hide most environment from the tests, which means
getting $HOME/$USERDIR to reset it later will fail.
With this change, we delete the variable when it wasn't set when starting the
test.
--HG--
branch : home-fix
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/test/unittest_lint.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/pylint/test/unittest_lint.py b/pylint/test/unittest_lint.py index 98fc225fe..37252c471 100644 --- a/pylint/test/unittest_lint.py +++ b/pylint/test/unittest_lint.py @@ -509,7 +509,7 @@ class ConfigTC(unittest.TestCase): def test_pylintrc(self): fake_home = tempfile.mkdtemp('fake-home') - home = os.environ[HOME] + home = os.environ.get(HOME, None) try: os.environ[HOME] = fake_home self.assertEqual(config.find_pylintrc(), None) @@ -519,7 +519,10 @@ class ConfigTC(unittest.TestCase): self.assertEqual(config.find_pylintrc(), None) finally: os.environ.pop('PYLINTRC', '') - os.environ[HOME] = home + if home is None: + del os.environ[HOME] + else: + os.environ[HOME] = home rmtree(fake_home, ignore_errors=True) reload(config) @@ -530,12 +533,15 @@ class ConfigTC(unittest.TestCase): 'a/b/c/__init__.py', 'a/b/c/d/__init__.py', 'a/b/c/d/e/.pylintrc']) fake_home = tempfile.mkdtemp('fake-home') - home = os.environ[HOME] + home = os.environ.get(HOME, None) try: os.environ[HOME] = fake_home self.assertEqual(config.find_pylintrc(), None) finally: - os.environ[HOME] = home + if home is None: + del os.environ[HOME] + else: + os.environ[HOME] = home os.rmdir(fake_home) results = {'a' : join(chroot, 'a', 'pylintrc'), 'a/b' : join(chroot, 'a', 'b', 'pylintrc'), @@ -550,7 +556,7 @@ class ConfigTC(unittest.TestCase): def test_pylintrc_parentdir_no_package(self): with tempdir() as chroot: fake_home = tempfile.mkdtemp('fake-home') - home = os.environ[HOME] + home = os.environ.get(HOME, None) os.environ[HOME] = fake_home try: create_files(['a/pylintrc', 'a/b/pylintrc', 'a/b/c/d/__init__.py']) @@ -564,7 +570,10 @@ class ConfigTC(unittest.TestCase): os.chdir(join(chroot, basedir)) self.assertEqual(config.find_pylintrc(), expected) finally: - os.environ[HOME] = home + if home is None: + del os.environ[HOME] + else: + os.environ[HOME] = home rmtree(fake_home, ignore_errors=True) |