Skip to content

Commit 297c142

Browse files
author
Val Brodsky
committed
Refactor teardown handling into a separate helper
1 parent 18b6cf1 commit 297c142

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

libs/labelbox/tests/conftest.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import re
88
import uuid
99
import time
10+
from labelbox.schema.project import Project
1011
import requests
1112
import pytest
1213
from types import SimpleNamespace
@@ -768,7 +769,7 @@ def configured_batch_project_with_label(client, dataset, data_row,
768769
@pytest.fixture
769770
def configured_batch_project_with_multiple_datarows(client, dataset, data_rows,
770771
wait_for_label_processing,
771-
rand_gen):
772+
rand_gen, teardown_helpers):
772773
"""Project with a batch having multiple datarows
773774
Project contains an ontology with 1 bbox tool
774775
Additionally includes a create_label method for any needed extra labels
@@ -787,18 +788,7 @@ def configured_batch_project_with_multiple_datarows(client, dataset, data_rows,
787788

788789
yield [project, dataset, data_rows]
789790

790-
featureSchemaIds = [tool.feature_schema_id for tool in ontology.tools]
791-
ontology = project.ontology()
792-
ontology_id = ontology.uid
793-
client = project.client
794-
795-
for label in project.labels():
796-
label.delete()
797-
798-
project.delete()
799-
client.delete_unused_ontology(ontology_id)
800-
for featureSchemaId in featureSchemaIds:
801-
project.client.delete_unused_feature_schema(featureSchemaId)
791+
teardown_helpers.teardown_project_labels_ontology_feature_schemas(project)
802792

803793

804794
@pytest.fixture
@@ -1181,3 +1171,37 @@ def requested_labeling_service(
11811171
labeling_service.request()
11821172

11831173
yield project, project.get_labeling_service()
1174+
1175+
1176+
class TearDownHelpers:
1177+
1178+
@staticmethod
1179+
def teardown_project_labels_ontology_feature_schemas(project: Project):
1180+
"""
1181+
Call this function to release project, labels, ontology and feature schemas in fixture teardown
1182+
1183+
NOTE: exception handling is not required as this is a fixture teardown
1184+
"""
1185+
ontology = project.ontology()
1186+
ontology_id = ontology.uid
1187+
client = project.client
1188+
1189+
# featureSchemaIds = [tool.feature_schema_id for tool in ontology_builder.tools]
1190+
featureSchemaIds = [
1191+
feature["featureSchemaId"]
1192+
for feature in ontology.normalized["classifications"]
1193+
]
1194+
1195+
labels = list(project.labels())
1196+
for label in labels:
1197+
label.delete()
1198+
1199+
project.delete()
1200+
client.delete_unused_ontology(ontology_id)
1201+
for featureSchemaId in featureSchemaIds:
1202+
project.client.delete_unused_feature_schema(featureSchemaId)
1203+
1204+
1205+
@pytest.fixture
1206+
def teardown_helpers():
1207+
return TearDownHelpers()

libs/labelbox/tests/data/annotation_import/conftest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import itertools
21
import uuid
32

43
from labelbox.schema.model_run import ModelRun
@@ -14,8 +13,6 @@
1413
from typing import Tuple, Type
1514
from labelbox.schema.annotation_import import LabelImport, AnnotationImportState
1615
from pytest import FixtureRequest
17-
from contextlib import suppress
18-
1916
"""
2017
The main fixtures of this library are configured_project and configured_project_by_global_key. Both fixtures generate data rows with a parametrize media type. They create the amount of data rows equal to the DATA_ROW_COUNT variable below. The data rows are generated with a factory fixture that returns a function that allows you to pass a global key. The ontologies are generated normalized and based on the MediaType given (i.e. only features supported by MediaType are created). This ontology is later used to obtain the correct annotations with the prediction_id_mapping and corresponding inferences. Each data row will have all possible annotations attached supported for the MediaType.
2118
"""

0 commit comments

Comments
 (0)