Skip to content

Commit d068392

Browse files
committed
Further test parallelization
1 parent 360c539 commit d068392

File tree

9 files changed

+46
-47
lines changed

9 files changed

+46
-47
lines changed

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[pytest]
2-
addopts = -s -vv -x --reruns 5 --reruns-delay 10 --durations=20
2+
addopts = -s -vv --reruns 5 --reruns-delay 10 --durations=20
33
markers =
44
slow: marks tests as slow (deselect with '-m "not slow"')

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ typeguard
1313
imagesize
1414
pyproj
1515
pygeotile
16-
typing-extensions
16+
typing-extensions
17+
pytest-xdist
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
1+
import pytest
2+
13
from labelbox import Model
4+
from labelbox.exceptions import ResourceNotFoundError
25

36

47
def test_model(client, configured_project, rand_gen):
5-
before = list(client.get_models())
6-
for m in before:
8+
# Get all
9+
models = list(client.get_models())
10+
for m in models:
711
assert isinstance(m, Model)
812

13+
# Create
914
ontology = configured_project.ontology()
10-
1115
data = {"name": rand_gen(str), "ontology_id": ontology.uid}
1216
model = client.create_model(data["name"], data["ontology_id"])
1317
assert model.name == data["name"]
1418

15-
after = list(client.get_models())
16-
assert len(after) == len(before) + 1
17-
assert model in after
18-
19+
# Get one
1920
model = client.get_model(model.uid)
2021
assert model.name == data["name"]
2122

22-
23-
def test_model_delete(client, model):
24-
before = list(client.get_models())
25-
26-
model = before[0]
23+
# Delete
2724
model.delete()
28-
29-
after = list(client.get_models())
30-
31-
assert len(before) == len(after) + 1
25+
with pytest.raises(ResourceNotFoundError):
26+
client.get_model(model.uid)

tests/integration/annotation_import/test_model_run.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def test_model_run_delete(client, model_run):
5252
models_after = list(client.get_models())
5353
model_after = models_after[0]
5454
after = list(model_after.model_runs())
55+
after_uids = {mr.uid for mr in after}
5556

56-
assert len(before) == len(after) + 1
57+
assert model_run.uid not in after_uids
5758

5859

5960
def test_model_run_update_config(model_run_with_training_metadata):
@@ -75,10 +76,11 @@ def test_model_run_get_config(model_run_with_training_metadata):
7576

7677

7778
def test_model_run_data_rows_delete(client, model_run_with_model_run_data_rows):
78-
models = list(client.get_models())
79-
model = models[0]
80-
model_runs = list(model.model_runs())
81-
model_run = model_runs[0]
79+
# models = list(client.get_models())
80+
# model = models[0]
81+
# model_runs = list(model.model_runs())
82+
# model_run = model_runs[0]
83+
model_run = model_run_with_model_run_data_rows
8284

8385
before = list(model_run.model_run_data_rows())
8486
annotation_data_row = before[0]

tests/integration/test_client_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_semantic_error(client):
4545
def test_timeout_error(client, project):
4646
with pytest.raises(labelbox.exceptions.TimeoutError) as excinfo:
4747
query_str = """query getOntology {
48-
project (where: {id: $%s}) {
48+
project (where: {id: %s}) {
4949
ontology {
5050
normalized
5151
}

tests/integration/test_data_row_metadata.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import uuid
55

66
from labelbox import DataRow, Dataset
7+
from labelbox.exceptions import MalformedQueryException
78
from labelbox.schema.data_row_metadata import DataRowMetadataField, DataRowMetadata, DataRowMetadataKind, DeleteDataRowMetadata, \
89
DataRowMetadataOntology, _parse_metadata_schema
910

@@ -17,7 +18,7 @@
1718
TEXT_SCHEMA_ID = "cko8s9r5v0001h2dk9elqdidh"
1819
CAPTURE_DT_SCHEMA_ID = "cko8sdzv70006h2dk8jg64zvb"
1920
PRE_COMPUTED_EMBEDDINGS_ID = 'ckrzang79000008l6hb5s6za1'
20-
CUSTOM_TEXT_SCHEMA_NAME = 'custom_text'
21+
CUSTOM_TEXT_SCHEMA_NAME = 'datarow_metadata_custom_text'
2122

2223
FAKE_NUMBER_FIELD = {
2324
"id": FAKE_SCHEMA_ID,
@@ -30,13 +31,16 @@
3031
@pytest.fixture
3132
def mdo(client):
3233
mdo = client.get_data_row_metadata_ontology()
33-
for schema in mdo.custom_fields:
34-
mdo.delete_schema(schema.name)
35-
mdo.create_schema(CUSTOM_TEXT_SCHEMA_NAME, DataRowMetadataKind.string)
34+
try:
35+
mdo.create_schema(CUSTOM_TEXT_SCHEMA_NAME, DataRowMetadataKind.string)
36+
except MalformedQueryException:
37+
# Do nothing if already exists
38+
pass
3639
mdo._raw_ontology = mdo._get_ontology()
3740
mdo._raw_ontology.append(FAKE_NUMBER_FIELD)
3841
mdo._build_ontology()
3942
yield mdo
43+
mdo.delete_schema(CUSTOM_TEXT_SCHEMA_NAME)
4044

4145

4246
@pytest.fixture
@@ -101,7 +105,8 @@ def test_export_empty_metadata(client, configured_project_with_label,
101105
def test_get_datarow_metadata_ontology(mdo):
102106
assert len(mdo.fields)
103107
assert len(mdo.reserved_fields)
104-
assert len(mdo.custom_fields) == 2
108+
# three are created by mdo fixture but there may be more
109+
assert len(mdo.custom_fields) >= 3
105110

106111
split = mdo.reserved_by_name["split"]["train"]
107112

tests/integration/test_data_rows.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import requests
88

99
from labelbox import DataRow
10+
from labelbox.exceptions import MalformedQueryException
1011
from labelbox.schema.task import Task
1112
from labelbox.schema.data_row_metadata import DataRowMetadataField, DataRowMetadataKind
1213
import labelbox.exceptions
@@ -20,18 +21,21 @@
2021
SPLIT_SCHEMA_ID, TEST_SPLIT_ID, EMBEDDING_SCHEMA_ID, TEXT_SCHEMA_ID,
2122
CAPTURE_DT_SCHEMA_ID
2223
].sort()
23-
CUSTOM_TEXT_SCHEMA_NAME = "custom_text"
24+
CUSTOM_TEXT_SCHEMA_NAME = "data_row_custom_text"
2425

2526

2627
@pytest.fixture
2728
def mdo(client):
2829
mdo = client.get_data_row_metadata_ontology()
29-
for schema in mdo.custom_fields:
30-
mdo.delete_schema(schema.name)
31-
mdo.create_schema(CUSTOM_TEXT_SCHEMA_NAME, DataRowMetadataKind.string)
30+
try:
31+
mdo.create_schema(CUSTOM_TEXT_SCHEMA_NAME, DataRowMetadataKind.string)
32+
except MalformedQueryException:
33+
# Do nothing if already exists
34+
pass
3235
mdo._raw_ontology = mdo._get_ontology()
3336
mdo._build_ontology()
3437
yield mdo
38+
mdo.delete_schema(CUSTOM_TEXT_SCHEMA_NAME)
3539

3640

3741
@pytest.fixture
@@ -415,7 +419,7 @@ def test_create_data_rows_with_named_metadata_field_class(
415419
"row1",
416420
DataRow.metadata_fields: [
417421
DataRowMetadataField(name='split', value='test'),
418-
DataRowMetadataField(name='custom_text', value='hello')
422+
DataRowMetadataField(name=CUSTOM_TEXT_SCHEMA_NAME, value='hello')
419423
]
420424
}
421425

@@ -430,7 +434,7 @@ def test_create_data_rows_with_named_metadata_field_class(
430434
'value': 'test'
431435
},
432436
{
433-
'name': 'custom_text',
437+
'name': CUSTOM_TEXT_SCHEMA_NAME,
434438
'value': 'hello'
435439
},
436440
]

tests/integration/test_project.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212

1313
def test_project(client, rand_gen):
14-
before = list(client.get_projects())
15-
for o in before:
16-
assert isinstance(o, Project)
1714

1815
data = {
1916
"name": rand_gen(str),
@@ -24,10 +21,6 @@ def test_project(client, rand_gen):
2421
assert project.name == data["name"]
2522
assert project.description == data["description"]
2623

27-
after = list(client.get_projects())
28-
assert len(after) == len(before) + 1
29-
assert project in after
30-
3124
project = client.get_project(project.uid)
3225
assert project.name == data["name"]
3326
assert project.description == data["description"]
@@ -44,9 +37,8 @@ def test_project(client, rand_gen):
4437
assert project.description == update_data["description"]
4538

4639
project.delete()
47-
final = list(client.get_projects())
48-
assert project not in final
49-
assert set(final) == set(before)
40+
projects = list(client.get_projects())
41+
assert project not in projects
5042

5143

5244
def test_update_project_resource_tags(client, rand_gen):

tests/integration/test_user_and_org.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ def test_user_and_org_projects(project):
1919

2020
assert project.created_by() == user
2121
assert project.organization() == org
22-
assert set(user.projects()) == user_projects.union({project})
23-
assert set(org.projects()) == org_projects.union({project})
22+
assert project in user_projects
23+
assert project in org_projects

0 commit comments

Comments
 (0)