Skip to content

Commit

Permalink
python: improve target availability check in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishek Gaikwad <[email protected]>
  • Loading branch information
gaikwadabhishek committed Jan 30, 2025
1 parent 45c69e4 commit de65d2b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/aistore/sdk/obj/object_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get(self, stream: bool, offset: Optional[int] = None) -> requests.Response:
resp.raise_for_status()
return resp

except ErrObjNotFound as _:
except ErrObjNotFound:
if self._uname:
return self._retry_with_new_smap(
HTTP_METHOD_GET,
Expand Down
13 changes: 9 additions & 4 deletions python/tests/integration/sdk/test_object_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
from tests.integration import CLUSTER_ENDPOINT, REMOTE_SET


def has_enough_targets():
"""Check if the cluster has at least two targets before running tests."""
try:
return len(Client(CLUSTER_ENDPOINT).cluster().get_info().tmap) >= 2
except Exception:
return False # Assume failure means insufficient targets or unreachable cluster (AuthN)


# pylint: disable=unused-variable, too-many-public-methods
class TestObjectOps(RemoteEnabledTest):
def setUp(self) -> None:
Expand Down Expand Up @@ -399,10 +407,7 @@ def test_get_object_from_url(self):
fetched_content = fetched_obj.get_reader().read_all()
self.assertEqual(content, fetched_content)

@unittest.skipIf(
len(Client(CLUSTER_ENDPOINT).cluster().get_info().tmap) < 2,
"Test requires more than one target",
)
@unittest.skipIf(not has_enough_targets(), "Test requires more than one target")
def test_get_object_direct(self):
"""
Test fetching objects directly from the target node.
Expand Down

0 comments on commit de65d2b

Please sign in to comment.