Skip to content

Commit 7ddace7

Browse files
committed
Only sets variables in finally if they exist before
1 parent 5f87022 commit 7ddace7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tests/unit/test_configs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ def test_credentials_from_env(self):
2727
self.assertEqual(config.app_id, 'foo-2')
2828
self.assertEqual(config.api_key, 'bar-2')
2929
finally:
30-
os.environ['ALGOLIA_APP_ID'] = old_app_id
31-
os.environ['ALGOLIA_API_KEY'] = old_api_key
30+
if old_app_id:
31+
os.environ['ALGOLIA_APP_ID'] = old_app_id
32+
33+
if old_api_key:
34+
os.environ['ALGOLIA_API_KEY'] = old_api_key
3235

3336
def test_app_id(self):
3437
self.assertEqual(self.config.app_id, 'foo')

0 commit comments

Comments
 (0)