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 3, 2024
1 parent 676d135 commit 29e634e
Showing 1 changed file with 17 additions and 0 deletions.
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 29e634e

Please sign in to comment.