Skip to content

Commit 97a429d

Browse files
committed
🧪 Set metric call counter in top level fixture
1 parent 4725b54 commit 97a429d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

‎tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,11 @@ def testing_exit(status: int) -> None:
163163

164164

165165
@pytest.fixture
166-
def create_plain_run(request, prevent_script_exit) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
166+
def create_plain_run(request, prevent_script_exit, mocker) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
167167
def testing_exit(status: int) -> None:
168168
raise SystemExit(status)
169169
with sv_run.Run() as run:
170+
run.metric_spy = mocker.spy(run, "_get_internal_metrics")
170171
yield run, setup_test_run(run, False, request)
171172
clear_out_files()
172173

‎tests/functional/test_run_class.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ def test_run_with_emissions_online(speedy_heartbeat, mock_co2_signal, create_pla
5858
run_created, _ = create_plain_run
5959
metric_interval = 1
6060
run_created._user_config.eco.co2_signal_api_token = "test_token"
61+
current_count = run_created.metric_spy.call_count
6162
run_created.config(enable_emission_metrics=True, system_metrics_interval=metric_interval)
62-
spy = mocker.spy(run_created, "_get_internal_metrics")
6363
while (
6464
"sustainability.emissions.total" not in requests.get(
6565
url=f"{run_created._user_config.server.url}/metrics/names",
6666
headers=run_created._headers,
6767
params={"runs": json.dumps([run_created.id])}).json()
68-
and spy.call_count < 4
68+
and run_created.metric_spy.call_count < 4
6969
):
7070
time.sleep(metric_interval)
7171
_run = RunObject(identifier=run_created.id)
@@ -85,7 +85,7 @@ def test_run_with_emissions_online(speedy_heartbeat, mock_co2_signal, create_pla
8585
# Check that total = previous total + latest delta
8686
_total_values = _metric_values[_total_metric_name].tolist()
8787
_delta_values = _metric_values[_delta_metric_name].tolist()
88-
assert len(_total_values) == spy.call_count
88+
assert len(_total_values) >= run_created.metric_spy.call_count - current_count
8989
for i in range(1, len(_total_values)):
9090
assert _total_values[i] == _total_values[i - 1] + _delta_values[i]
9191

0 commit comments

Comments
 (0)