tests: Delete env vars that could interfere

Several environment variables can influence which config file yamllint
chooses to use [1]. Before this change, if you set those environment
variables and ran “python -m unittest discover”, then you could cause
certain tests to use the wrong config file and fail.

Fixes #621.

[1]: <152ba20f33/yamllint/cli.py (L180-L188)>
This commit is contained in:
Jason Yundt 2023-12-30 15:14:43 -05:00 committed by Adrien Vergé
parent f3adc585d2
commit 92688d2bb0

View File

@ -66,6 +66,26 @@ def utf8_available():
return False
def setUpModule():
# yamllint uses these environment variables to find a config file.
env_vars_that_could_interfere = (
'YAMLLINT_CONFIG_FILE',
'XDG_CONFIG_HOME',
# These variables are used to determine where the users home
# directory is. See
# https://docs.python.org/3/library/os.path.html#os.path.expanduser
'HOME',
'USERPROFILE',
'HOMEPATH',
'HOMEDRIVE'
)
for name in env_vars_that_could_interfere:
try:
del os.environ[name]
except KeyError:
pass
class CommandLineTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):