Skip to content

Commit 4c50974

Browse files
lonly7starLiu, Sichenshifucun
authored
fix flaky test on set_api_key_test.py::TestApiKey::test_query_no_api_key and set_api_key_test.py::TestApiKey::test_send_request_no_api_key (#175)
* fix flaky test on set_api_key_test * restore gitinore Co-authored-by: Liu, Sichen <[email protected]> Co-authored-by: Bo Xu <[email protected]>
1 parent d61065d commit 4c50974

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

datacommons/test/set_api_key_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ class TestApiKey(unittest.TestCase):
7676
"""Unit test for setting or not setting the API Key."""
7777
@patch('six.moves.urllib.request.urlopen', side_effect=request_mock)
7878
def test_query_no_api_key(self, urlopen):
79-
del os.environ[utils._ENV_VAR_API_KEY]
79+
if os.getenv(utils._ENV_VAR_API_KEY):
80+
del os.environ[utils._ENV_VAR_API_KEY]
8081
# Issue a dummy SPARQL query that tells the mock to not expect a key
8182
self.assertEqual(dc.query(_SPARQL_NO_KEY), [])
8283

8384
@patch('six.moves.urllib.request.urlopen', side_effect=request_mock)
8485
def test_send_request_no_api_key(self, urlopen):
85-
del os.environ[utils._ENV_VAR_API_KEY]
86+
if os.getenv(utils._ENV_VAR_API_KEY):
87+
del os.environ[utils._ENV_VAR_API_KEY]
8688
# Issue a dummy url that tells the mock to not expect a key
8789
self.assertEqual(utils._send_request(_SEND_REQ_NO_KEY, {'foo': ['bar']}), {})
8890

0 commit comments

Comments
 (0)