Skip to content

Commit 619828a

Browse files
committed
Use test name for tag via fixture and add CI tag if relevant
1 parent 2da7784 commit 619828a

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

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_run_class.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ def test_log_metrics(
6464
retention_period="1 hour",
6565
)
6666

67-
run.update_tags(["simvue_client_unit_tests", "test_log_metrics"])
68-
6967
# Speed up the read rate for this test
7068
run._dispatcher._max_buffer_size = 10
7169
run._dispatcher._max_read_rate *= 10
@@ -110,31 +108,27 @@ def test_log_metrics(
110108
def test_log_metrics_offline(create_test_run_offline: tuple[sv_run.Run, dict]) -> None:
111109
METRICS = {"a": 10, "b": 1.2, "c": 2}
112110
run, _ = create_test_run_offline
113-
run.update_tags(["simvue_client_unit_tests", "test_log_metrics"])
114111
run.log_metrics(METRICS)
115112

116113

117114
@pytest.mark.run
118115
def test_log_events(create_test_run: tuple[sv_run.Run, dict]) -> None:
119116
EVENT_MSG = "Hello world!"
120117
run, _ = create_test_run
121-
run.update_tags(["simvue_client_unit_tests", "test_log_events"])
122118
run.log_event(EVENT_MSG)
123119

124120

125121
@pytest.mark.run
126122
def test_log_events_offline(create_test_run_offline: tuple[sv_run.Run, dict]) -> None:
127123
EVENT_MSG = "Hello world!"
128124
run, _ = create_test_run_offline
129-
run.update_tags(["simvue_client_unit_tests", "test_log_events"])
130125
run.log_event(EVENT_MSG)
131126

132127

133128
@pytest.mark.run
134129
def test_update_metadata(create_test_run: tuple[sv_run.Run, dict]) -> None:
135130
METADATA = {"a": 10, "b": 1.2, "c": "word"}
136131
run, _ = create_test_run
137-
run.update_tags(["simvue_client_unit_tests", "test_update_metadata"])
138132
run.update_metadata(METADATA)
139133

140134

@@ -144,7 +138,6 @@ def test_update_metadata_offline(
144138
) -> None:
145139
METADATA = {"a": 10, "b": 1.2, "c": "word"}
146140
run, _ = create_test_run_offline
147-
run.update_tags(["simvue_client_unit_tests", "test_update_metadata"])
148141
run.update_metadata(METADATA)
149142

150143

0 commit comments

Comments
 (0)