Skip to content

Commit 9e41e82

Browse files
author
Val Brodsky
committed
Add config for fixture profiling
1 parent 6599087 commit 9e41e82

File tree

4 files changed

+25
-37
lines changed

4 files changed

+25
-37
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ test-local: build-image
1313
-e LABELBOX_TEST_ENVIRON="local" \
1414
-e DA_GCP_LABELBOX_API_KEY=${DA_GCP_LABELBOX_API_KEY} \
1515
-e LABELBOX_TEST_API_KEY_LOCAL=${LABELBOX_TEST_API_KEY_LOCAL} \
16+
-e FIXTURE_PROFILE=true \
1617
local/labelbox-python:test pytest $(PATH_TO_TEST)
1718

1819
test-staging: build-image

tests/integration/annotation_import/conftest.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ def get_data_row_id(indx=0):
498498

499499
@pytest.fixture
500500
def configured_project(client, initial_dataset, ontology, rand_gen, image_url):
501-
start_time = time.time()
502501
dataset = initial_dataset
503502
project = client.create_project(name=rand_gen(str),
504503
queue_mode=QueueMode.Batch)
@@ -515,15 +514,12 @@ def configured_project(client, initial_dataset, ontology, rand_gen, image_url):
515514
num_rows += 1
516515
project._wait_until_data_rows_are_processed(data_row_ids=data_row_ids,
517516
sleep_interval=3)
518-
if pytest.data_row_report:
519-
pytest.data_row_report['times'] += time.time() - start_time
520-
pytest.data_row_report['num_rows'] += num_rows
517+
521518
project.create_batch(
522519
rand_gen(str),
523520
data_row_ids, # sample of data row objects
524521
5 # priority between 1(Highest) - 5(lowest)
525522
)
526-
print("After creating batch ", time.time() - start_time)
527523
project.data_row_ids = data_row_ids
528524

529525
yield project
@@ -579,8 +575,6 @@ def dataset_conversation_entity(client, rand_gen, conversation_entity_data_row,
579575
@pytest.fixture
580576
def configured_project_with_one_data_row(client, ontology, rand_gen,
581577
initial_dataset, image_url):
582-
start_time = time.time()
583-
584578
project = client.create_project(name=rand_gen(str),
585579
description=rand_gen(str),
586580
queue_mode=QueueMode.Batch)
@@ -594,9 +588,6 @@ def configured_project_with_one_data_row(client, ontology, rand_gen,
594588
project._wait_until_data_rows_are_processed(data_row_ids=data_row_ids,
595589
sleep_interval=3)
596590

597-
if pytest.data_row_report:
598-
pytest.data_row_report['times'] += time.time() - start_time
599-
pytest.data_row_report['num_rows'] += 1
600591
batch = project.create_batch(
601592
rand_gen(str),
602593
data_row_ids, # sample of data row objects

tests/integration/annotation_import/test_data_types.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,15 @@ def create_data_row_for_project(project, dataset, data_row_ndjson, batch_name):
135135
AudioData, ConversationData, DicomData, DocumentData, HTMLData, ImageData,
136136
TextData
137137
])
138-
def test_import_data_types(client, configured_project, initial_dataset,
139-
rand_gen, data_row_json_by_data_type,
140-
annotations_by_data_type, data_type_class,
141-
one_datarow):
138+
def test_import_data_types(
139+
client,
140+
configured_project,
141+
initial_dataset,
142+
rand_gen,
143+
data_row_json_by_data_type,
144+
annotations_by_data_type,
145+
data_type_class,
146+
):
142147

143148
project = configured_project
144149
project_id = project.uid

tests/integration/conftest.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
IMG_URL = "https://picsum.photos/200/300.jpg"
2929
SMALL_DATASET_URL = "https://storage.googleapis.com/lb-artifacts-testing-public/sdk_integration_test/potato.jpeg"
30-
DATA_ROW_PROCESSING_WAIT_TIMEOUT_SECONDS = 30
31-
DATA_ROW_PROCESSING_WAIT_SLEEP_INTERNAL_SECONDS = 5
3230

3331

3432
class Environ(Enum):
@@ -458,10 +456,8 @@ def configured_batch_project_with_label(project, dataset, data_row,
458456
One label is already created and yielded when using fixture
459457
"""
460458
data_rows = [dr.uid for dr in list(dataset.data_rows())]
461-
project._wait_until_data_rows_are_processed(
462-
data_row_ids=data_rows,
463-
wait_processing_max_seconds=DATA_ROW_PROCESSING_WAIT_TIMEOUT_SECONDS,
464-
sleep_interval=DATA_ROW_PROCESSING_WAIT_SLEEP_INTERNAL_SECONDS)
459+
project._wait_until_data_rows_are_processed(data_row_ids=data_rows,
460+
sleep_interval=3)
465461
project.create_batch("test-batch", data_rows)
466462
project.data_row_ids = data_rows
467463

@@ -604,7 +600,6 @@ def configured_project_with_complex_ontology(client, initial_dataset, rand_gen,
604600
project.setup(editor, ontology.asdict())
605601

606602
yield [project, data_row]
607-
dataset.delete()
608603
project.delete()
609604

610605

@@ -825,35 +820,31 @@ def upload_invalid_data_rows_for_dataset(dataset: Dataset):
825820
task.wait_till_done()
826821

827822

828-
@pytest.mark.skipif("FIXTURE_PROFILE" not in os.environ)
829823
def pytest_configure():
830824
pytest.report = defaultdict(int)
831-
pytest.data_row_report = {'times': 0, 'num_rows': 0}
832825

833826

834-
@pytest.mark.skipif("FIXTURE_PROFILE" not in os.environ)
835827
@pytest.hookimpl(hookwrapper=True)
836-
def pytest_fixture_setup(fixturedef, request):
828+
def pytest_fixture_setup(fixturedef):
837829
start = time.time()
838830
yield
839-
840831
end = time.time()
841832

842833
exec_time = end - start
843-
pytest.report[fixturedef.argname] += exec_time
834+
if "FIXTURE_PROFILE" in os.environ:
835+
pytest.report[fixturedef.argname] += exec_time
844836

845837

846-
@pytest.mark.skipif("FIXTURE_PROFILE" not in os.environ)
847838
@pytest.fixture(scope='session', autouse=True)
848839
def print_perf_summary():
849840
yield
850841

851-
sorted_dict = dict(
852-
sorted(pytest.report.items(), key=lambda item: item[1], reverse=True))
853-
num_of_entries = 10 if len(sorted_dict) >= 10 else len(sorted_dict)
854-
slowest_fixtures = [
855-
(aaa, sorted_dict[aaa]) for aaa in islice(sorted_dict, num_of_entries)
856-
]
857-
print("\nTop slowest fixtures:\n", slowest_fixtures, file=sys.stderr)
858-
print("Data row report:\n", pytest.data_row_report, file=sys.stderr)
859-
# assert False
842+
if "FIXTURE_PROFILE" in os.environ:
843+
sorted_dict = dict(
844+
sorted(pytest.report.items(),
845+
key=lambda item: item[1],
846+
reverse=True))
847+
num_of_entries = 10 if len(sorted_dict) >= 10 else len(sorted_dict)
848+
slowest_fixtures = [(aaa, sorted_dict[aaa])
849+
for aaa in islice(sorted_dict, num_of_entries)]
850+
print("\nTop slowest fixtures:\n", slowest_fixtures, file=sys.stderr)

0 commit comments

Comments
 (0)