Skip to content

Commit d94f98a

Browse files
authored
Merge pull request #348 from simvue-io/338-consistency-of-folders-tags-for-ci-test-runs
Fix consistency of folders tags for ci test runs
2 parents 2da7784 + 27ce952 commit d94f98a

File tree

8 files changed

+39
-38
lines changed

8 files changed

+39
-38
lines changed

tests/functional/test_run_offline_folder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_basic_run_folder(self):
2424
pass
2525

2626
name = "test-%s" % str(uuid.uuid4())
27-
folder = "/test-%s" % str(uuid.uuid4())
27+
folder = "/simvue_unit_testing"
2828
metadata = {str(uuid.uuid4()): 100 * random.random()}
2929
run = Run("offline")
3030
run.init(name, folder=folder)

tests/refactor/conftest.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,48 +42,53 @@ def log_messages(caplog):
4242

4343

4444
@pytest.fixture
45-
def create_test_run() -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
45+
def create_test_run(request) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
4646
with sv_run.Run() as run:
47-
yield run, setup_test_run(run, True)
47+
yield run, setup_test_run(run, True, request)
4848

4949

5050
@pytest.fixture
51-
def create_test_run_offline(mocker: pytest_mock.MockerFixture) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
51+
def create_test_run_offline(mocker: pytest_mock.MockerFixture, request) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
5252
with tempfile.TemporaryDirectory() as temp_d:
5353
mocker.patch.object(simvue.utilities, "get_offline_directory", lambda *_: temp_d)
5454
with sv_run.Run("offline") as run:
55-
yield run, setup_test_run(run, True)
55+
yield run, setup_test_run(run, True, request)
5656

5757

5858
@pytest.fixture
59-
def create_plain_run() -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
59+
def create_plain_run(request) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
6060
with sv_run.Run() as run:
61-
yield run, setup_test_run(run, False)
61+
yield run, setup_test_run(run, False, request)
6262

6363

6464
@pytest.fixture
65-
def create_plain_run_offline(mocker: pytest_mock.MockerFixture) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
65+
def create_plain_run_offline(mocker: pytest_mock.MockerFixture, request) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
6666
with tempfile.TemporaryDirectory() as temp_d:
6767
mocker.patch.object(simvue.utilities, "get_offline_directory", lambda *_: temp_d)
6868
with sv_run.Run("offline") as run:
6969

70-
yield run, setup_test_run(run, False)
70+
yield run, setup_test_run(run, False, request)
7171

7272

73-
def setup_test_run(run: sv_run.Run, create_objects: bool):
73+
def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.FixtureRequest):
7474
fix_use_id: str = str(uuid.uuid4()).split('-', 1)[0]
7575
TEST_DATA = {
7676
"event_contains": "sent event",
7777
"metadata": {
7878
"test_engine": "pytest",
7979
"test_identifier": fix_use_id
8080
},
81-
"folder": f"/simvue_unit_testing/{fix_use_id}"
81+
"folder": f"/simvue_unit_testing/{fix_use_id}",
82+
"tags": ["simvue_client_unit_tests", request.node.name]
8283
}
84+
85+
if os.environ.get("CI"):
86+
TEST_DATA["tags"].append("ci")
87+
8388
run.config(suppress_errors=False)
8489
run.init(
8590
name=f"test_run_{TEST_DATA['metadata']['test_identifier']}",
86-
tags=["simvue_client_unit_tests"],
91+
tags=TEST_DATA["tags"],
8792
folder=TEST_DATA["folder"],
8893
visibility="tenant",
8994
retention_period="1 hour"

tests/refactor/test_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ def test_run_deletion(create_test_run: tuple[sv_run.Run, dict]) -> None:
175175
@pytest.mark.client(depends=PRE_DELETION_TESTS)
176176
def test_runs_deletion(create_test_run: tuple[sv_run.Run, dict]) -> None:
177177
run, run_data = create_test_run
178-
run.update_tags(["simvue_client_unit_tests", "test_runs_deletion"])
179178
run.close()
180179
client = svc.Client()
181180
assert len(client.delete_runs(run_data["folder"])) > 0
@@ -185,7 +184,6 @@ def test_runs_deletion(create_test_run: tuple[sv_run.Run, dict]) -> None:
185184
@pytest.mark.client(depends=PRE_DELETION_TESTS + ["test_runs_deletion"])
186185
def test_folder_deletion(create_test_run: tuple[sv_run.Run, dict]) -> None:
187186
run, run_data = create_test_run
188-
run.update_tags(["simvue_client_unit_tests", "test_folder_deletion"])
189187
run.close()
190188
client = svc.Client()
191189
# This test is called last, one run created so expect length 1

tests/refactor/test_executor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
@pytest.mark.executor
99
@pytest.mark.parametrize("successful", (True, False), ids=("successful", "failing"))
1010
def test_executor_add_process(
11-
successful: bool
11+
successful: bool,
12+
request: pytest.FixtureRequest
1213
) -> None:
1314
run = simvue.Run()
1415
completion_trigger = multiprocessing.Event()
1516
run.init(
1617
f"test_executor_{'success' if successful else 'fail'}",
17-
tags=["simvue_client_unit_tests"],
18+
tags=["simvue_client_unit_tests", request.node.name],
1819
folder="/simvue_unit_test_folder"
1920
)
2021

tests/refactor/test_run_class.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_log_metrics(
3232
overload_buffer: bool,
3333
setup_logging: "CountingLogHandler",
3434
mocker,
35+
request: pytest.FixtureRequest,
3536
visibility: typing.Union[typing.Literal["public", "tenant"], list[str], None]
3637
) -> None:
3738
METRICS = {"a": 10, "b": 1.2}
@@ -47,7 +48,7 @@ def test_log_metrics(
4748
with pytest.raises(RuntimeError):
4849
run.init(
4950
name=f"test_run_{str(uuid.uuid4()).split('-', 1)[0]}",
50-
tags=["simvue_client_unit_tests"],
51+
tags=["simvue_client_unit_tests", request.node.name],
5152
folder="/simvue_unit_testing",
5253
retention_period="1 hour",
5354
visibility=visibility,
@@ -57,15 +58,13 @@ def test_log_metrics(
5758

5859
run.init(
5960
name=f"test_run_{str(uuid.uuid4()).split('-', 1)[0]}",
60-
tags=["simvue_client_unit_tests"],
61+
tags=["simvue_client_unit_tests", request.node.name],
6162
folder="/simvue_unit_testing",
6263
visibility=visibility,
6364
resources_metrics_interval=1,
6465
retention_period="1 hour",
6566
)
6667

67-
run.update_tags(["simvue_client_unit_tests", "test_log_metrics"])
68-
6968
# Speed up the read rate for this test
7069
run._dispatcher._max_buffer_size = 10
7170
run._dispatcher._max_read_rate *= 10
@@ -110,31 +109,27 @@ def test_log_metrics(
110109
def test_log_metrics_offline(create_test_run_offline: tuple[sv_run.Run, dict]) -> None:
111110
METRICS = {"a": 10, "b": 1.2, "c": 2}
112111
run, _ = create_test_run_offline
113-
run.update_tags(["simvue_client_unit_tests", "test_log_metrics"])
114112
run.log_metrics(METRICS)
115113

116114

117115
@pytest.mark.run
118116
def test_log_events(create_test_run: tuple[sv_run.Run, dict]) -> None:
119117
EVENT_MSG = "Hello world!"
120118
run, _ = create_test_run
121-
run.update_tags(["simvue_client_unit_tests", "test_log_events"])
122119
run.log_event(EVENT_MSG)
123120

124121

125122
@pytest.mark.run
126123
def test_log_events_offline(create_test_run_offline: tuple[sv_run.Run, dict]) -> None:
127124
EVENT_MSG = "Hello world!"
128125
run, _ = create_test_run_offline
129-
run.update_tags(["simvue_client_unit_tests", "test_log_events"])
130126
run.log_event(EVENT_MSG)
131127

132128

133129
@pytest.mark.run
134130
def test_update_metadata(create_test_run: tuple[sv_run.Run, dict]) -> None:
135131
METADATA = {"a": 10, "b": 1.2, "c": "word"}
136132
run, _ = create_test_run
137-
run.update_tags(["simvue_client_unit_tests", "test_update_metadata"])
138133
run.update_metadata(METADATA)
139134

140135

@@ -144,13 +139,12 @@ def test_update_metadata_offline(
144139
) -> None:
145140
METADATA = {"a": 10, "b": 1.2, "c": "word"}
146141
run, _ = create_test_run_offline
147-
run.update_tags(["simvue_client_unit_tests", "test_update_metadata"])
148142
run.update_metadata(METADATA)
149143

150144

151145
@pytest.mark.run
152146
@pytest.mark.parametrize("multi_threaded", (True, False), ids=("multi", "single"))
153-
def test_runs_multiple_parallel(multi_threaded: bool) -> None:
147+
def test_runs_multiple_parallel(multi_threaded: bool, request: pytest.FixtureRequest) -> None:
154148
N_RUNS: int = 2
155149
if multi_threaded:
156150

@@ -159,7 +153,7 @@ def thread_func(index: int) -> tuple[int, list[dict[str, typing.Any]], str]:
159153
run.config(suppress_errors=False)
160154
run.init(
161155
name=f"test_runs_multiple_{index + 1}",
162-
tags=["simvue_client_unit_tests", "test_multi_run_threaded"],
156+
tags=["simvue_client_unit_tests", request.node.name],
163157
folder="/simvue_unit_testing",
164158
retention_period="1 hour",
165159
)
@@ -196,7 +190,7 @@ def thread_func(index: int) -> tuple[int, list[dict[str, typing.Any]], str]:
196190
run_1.config(suppress_errors=False)
197191
run_1.init(
198192
name="test_runs_multiple_unthreaded_1",
199-
tags=["simvue_client_unit_tests", "test_multi_run_unthreaded"],
193+
tags=["simvue_client_unit_tests", request.node.name],
200194
folder="/simvue_unit_testing",
201195
retention_period="1 hour",
202196
)
@@ -238,7 +232,7 @@ def thread_func(index: int) -> tuple[int, list[dict[str, typing.Any]], str]:
238232

239233

240234
@pytest.mark.run
241-
def test_runs_multiple_series() -> None:
235+
def test_runs_multiple_series(request: pytest.FixtureRequest) -> None:
242236
N_RUNS: int = 2
243237

244238
metrics = []
@@ -250,7 +244,7 @@ def test_runs_multiple_series() -> None:
250244
run.config(suppress_errors=False)
251245
run.init(
252246
name=f"test_runs_multiple_series_{index}",
253-
tags=["simvue_client_unit_tests", "test_multi_run_series"],
247+
tags=["simvue_client_unit_tests", request.node.name],
254248
folder="/simvue_unit_testing",
255249
retention_period="1 hour",
256250
)
@@ -284,7 +278,7 @@ def test_runs_multiple_series() -> None:
284278
@pytest.mark.run
285279
@pytest.mark.parametrize("post_init", (True, False), ids=("pre-init", "post-init"))
286280
def test_suppressed_errors(
287-
setup_logging: "CountingLogHandler", post_init: bool
281+
setup_logging: "CountingLogHandler", post_init: bool, request: pytest.FixtureRequest
288282
) -> None:
289283
setup_logging.captures = ["Skipping call to"]
290284

@@ -300,7 +294,7 @@ def test_suppressed_errors(
300294
run.init(
301295
name="test_suppressed_errors",
302296
folder="/simvue_unit_testing",
303-
tags=["simvue_client_unit_tests"],
297+
tags=["simvue_client_unit_tests", request.node.name],
304298
retention_period="1 hour"
305299
)
306300

@@ -323,11 +317,11 @@ def test_bad_run_arguments() -> None:
323317
run.init("sdas", [34])
324318

325319

326-
def test_set_folder_details() -> None:
320+
def test_set_folder_details(request: pytest.FixtureRequest) -> None:
327321
with sv_run.Run() as run:
328-
folder_name: str ="/simvue_unit_test_folder"
322+
folder_name: str ="/simvue_unit_tests"
329323
description: str = "test description"
330-
tags: list[str] = ["simvue_client_unit_tests", "test_set_folder_details"]
324+
tags: list[str] = ["simvue_client_unit_tests", request.node.name]
331325
run.init(folder=folder_name)
332326
run.set_folder_details(path=folder_name, tags=tags, description=description)
333327

tests/unit/test_run_init_folder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_run_init_folder():
1515
with pytest.raises(RuntimeError) as exc_info:
1616
run.init(
1717
metadata={"dataset.x1_lower": x1_lower, "dataset.x1_upper": x1_upper},
18-
tags=["tag_1", "tag_2"],
18+
tags=["tag_1", "tag_2", "test_run_init_folder"],
1919
folder="test_folder",
2020
description="A test to validate folder input passed into run.init",
2121
retention_period="1 hour",

tests/unit/test_run_init_metadata.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def test_run_init_metadata():
1515
with pytest.raises(RuntimeError) as exc_info:
1616
run.init(metadata={'dataset.x1_lower': x1_lower, 'dataset.x1_upper': x1_upper},
1717
description="A test to validate inputs passed into metadata dictionary",
18-
retention_period="1 hour"
18+
retention_period="1 hour",
19+
folder="/simvue_unit_testing",
20+
tags=["simvue_client_unit_tests", "test_run_init_metadata"]
1921
)
2022

2123
assert "Input should be a valid integer" in str(exc_info.value)

tests/unit/test_run_init_tags.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def test_run_init_tags():
1515
with pytest.raises(RuntimeError) as exc_info:
1616
run.init(metadata={'dataset.x1_lower': x1_lower, 'dataset.x1_upper': x1_upper}, tags=1,
1717
description="A test to validate tag inputs passed into run.init",
18-
retention_period="1 hour"
18+
retention_period="1 hour",
19+
folder="/simvue_unit_testing"
1920
)
2021

2122
assert "Input should be a valid list" in str(exc_info.value)

0 commit comments

Comments
 (0)