Skip to content

Commit

Permalink
Fix test_base_client.py
Browse files Browse the repository at this point in the history
It was impure, changing environ variable and thereby messing other tests. This commit wraps these tests in a decorator saving and restoring os.environ.
  • Loading branch information
aversey committed Jul 2, 2024
1 parent 4b4ae38 commit 28ba397
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion locust_benchmark/create_feature_group.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from common.hopsworks_client import HopsworksClient

if __name__ == "__main__":

hopsworks_client = HopsworksClient()
fg = hopsworks_client.get_or_create_fg()
hopsworks_client.insert_data(fg)
Expand Down
17 changes: 17 additions & 0 deletions python/tests/client/test_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,29 @@
#

import os
from functools import wraps

import pytest
import requests
from hsfs.client.base import Client
from hsfs.client.exceptions import RestAPIError


def changes_environ(f):
@wraps(f)
def g(*args, **kwds):
old_environ = os.environ.copy()
try:
return f(*args, **kwds)
finally:
os.environ.clear()
os.environ.update(old_environ)

return g


class TestBaseClient:
@changes_environ
def test_valid_token_no_retires(self, mocker):
# Arrange
os.environ[Client.REST_ENDPOINT] = "True"
Expand All @@ -48,6 +63,7 @@ def test_valid_token_no_retires(self, mocker):
# Assert
assert spy_retry_token_expired.call_count == 0

@changes_environ
def test_invalid_token_retires(self, mocker):
# Arrange
os.environ[Client.REST_ENDPOINT] = "True"
Expand Down Expand Up @@ -77,6 +93,7 @@ def test_invalid_token_retires(self, mocker):
# Assert
assert spy_retry_token_expired.call_count == 10

@changes_environ
def test_invalid_token_retires_backoff_break(self, mocker):
# Arrange
os.environ[Client.REST_ENDPOINT] = "True"
Expand Down

0 comments on commit 28ba397

Please sign in to comment.