Skip to content

Commit

Permalink
Fix TestConfig unit tests by removing other possible environments.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Jul 30, 2016
1 parent 7caf9cd commit cfcc12b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class TestConfig(object):
def _assert_config_read(environment, mock_config):
mock_instance = mock_config.return_value
Config.CONFIG = None # Force config file reload
prev_environment = os.environ.get(environment)
prev_environment = {}
for env_name in ['APPDATA', 'HOME', 'XDG_CONFIG_HOME']:
if env_name in os.environ:
prev_environment[env_name] = os.environ.get(env_name)
del os.environ[env_name]
os.environ[environment] = '/MOCK'

module_dir = os.path.dirname(sys.modules['praw'].__file__)
Expand All @@ -26,10 +30,11 @@ def _assert_config_read(environment, mock_config):
mock_instance.read.assert_called_with(locations)
finally:
Config.CONFIG = None # Force config file reload
if prev_environment:
os.environ[environment] = prev_environment
else:
del os.environ[environment]
for env_name in prev_environment:
if prev_environment[env_name] is None:
del os.environ[env_name]
else:
os.environ[env_name] = prev_environment[env_name]

@mock.patch('six.moves.configparser.RawConfigParser')
def test_load_ini_from_appdata(self, mock_config):
Expand Down

0 comments on commit cfcc12b

Please sign in to comment.