Skip to content

Commit 89bcefd

Browse files
committed
_cleanup_model
1 parent f32a0be commit 89bcefd

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

tests/integrations/test_cloud.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from io import StringIO
44

55
import pytest
6+
from lightning_sdk import Teamspace
67
from lightning_sdk.lightning_cloud.rest_client import GridRestClient
78
from lightning_sdk.utils.resolve import _resolve_teamspace
89
from litmodels import download_model, upload_model
@@ -13,6 +14,18 @@
1314
LIT_TEAMSPACE = "LitModels"
1415

1516

17+
def _cleanup_model(teamspace: Teamspace, model_name: str) -> None:
18+
"""Cleanup model from the teamspace."""
19+
client = GridRestClient()
20+
# cleaning created models as each test run shall have unique model name
21+
model = client.models_store_get_model_by_name(
22+
project_owner_name=teamspace.owner.name,
23+
project_name=teamspace.name,
24+
model_name=model_name,
25+
)
26+
client.models_store_delete_model(project_id=teamspace.id, model_id=model.id)
27+
28+
1629
@pytest.mark.cloud()
1730
def test_upload_download_model(tmp_path):
1831
"""Verify that the model is uploaded to the teamspace"""
@@ -44,14 +57,7 @@ def test_upload_download_model(tmp_path):
4457
assert os.path.isfile(os.path.join(tmp_path, file))
4558

4659
# CLEANING
47-
client = GridRestClient()
48-
# cleaning created models as each test run shall have unique model name
49-
model = client.models_store_get_model_by_name(
50-
project_owner_name=teamspace.owner.name,
51-
project_name=teamspace.name,
52-
model_name=model_name,
53-
)
54-
client.models_store_delete_model(project_id=teamspace.id, model_id=model.id)
60+
_cleanup_model(teamspace, model_name)
5561

5662

5763
@pytest.mark.parametrize(
@@ -84,11 +90,4 @@ def test_lightning_default_checkpointing(importing, tmp_path):
8490
trainer.fit(BoringModel())
8591

8692
# CLEANING
87-
client = GridRestClient()
88-
# cleaning created models as each test run shall have unique model name
89-
model = client.models_store_get_model_by_name(
90-
project_owner_name=teamspace.owner.name,
91-
project_name=teamspace.name,
92-
model_name=model_name,
93-
)
94-
client.models_store_delete_model(project_id=teamspace.id, model_id=model.id)
93+
_cleanup_model(teamspace, model_name)

0 commit comments

Comments
 (0)