Skip to content

Commit 214c765

Browse files
committed
Fix test_base_client.py
It was impure, changing environ variable and thereby messing other tests. This commit wraps these tests in a decorator saving and restoring os.environ.
1 parent d7384d5 commit 214c765

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

locust_benchmark/create_feature_group.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from common.hopsworks_client import HopsworksClient
22

33
if __name__ == "__main__":
4-
54
hopsworks_client = HopsworksClient()
65
fg = hopsworks_client.get_or_create_fg()
76
hopsworks_client.insert_data(fg)

python/tests/client/test_base_client.py

+17
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,29 @@
1515
#
1616

1717
import os
18+
from functools import wraps
1819

1920
import pytest
2021
import requests
2122
from hsfs.client.base import Client
2223
from hsfs.client.exceptions import RestAPIError
2324

2425

26+
def changes_environ(f):
27+
@wraps(f)
28+
def g(*args, **kwds):
29+
old_environ = os.environ.copy()
30+
try:
31+
return f(*args, **kwds)
32+
finally:
33+
os.environ.clear()
34+
os.environ.update(old_environ)
35+
36+
return g
37+
38+
2539
class TestBaseClient:
40+
@changes_environ
2641
def test_valid_token_no_retires(self, mocker):
2742
# Arrange
2843
os.environ[Client.REST_ENDPOINT] = "True"
@@ -48,6 +63,7 @@ def test_valid_token_no_retires(self, mocker):
4863
# Assert
4964
assert spy_retry_token_expired.call_count == 0
5065

66+
@changes_environ
5167
def test_invalid_token_retires(self, mocker):
5268
# Arrange
5369
os.environ[Client.REST_ENDPOINT] = "True"
@@ -77,6 +93,7 @@ def test_invalid_token_retires(self, mocker):
7793
# Assert
7894
assert spy_retry_token_expired.call_count == 10
7995

96+
@changes_environ
8097
def test_invalid_token_retires_backoff_break(self, mocker):
8198
# Arrange
8299
os.environ[Client.REST_ENDPOINT] = "True"

0 commit comments

Comments
 (0)