Skip to content

Commit 1a89829

Browse files
authored
✅ Fixes flaky tests/unit/isolated/test_tracing.py::test_middleware_restrictions_opentelemetry_is_second_middleware (#8593)
1 parent 5a0cd22 commit 1a89829

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

packages/pytest-simcore/src/pytest_simcore/environment_configs.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import logging
77
import re
8+
from copy import deepcopy
89
from pathlib import Path
910
from typing import Any
1011

@@ -86,12 +87,20 @@ def skip_if_no_external_envfile(external_envfile_dict: EnvVarsDict) -> None:
8687

8788

8889
@pytest.fixture(scope="session")
89-
def env_devel_dict(env_devel_file: Path) -> EnvVarsDict:
90+
def _env_devel_dict_session(env_devel_file: Path) -> EnvVarsDict:
9091
assert env_devel_file.exists()
9192
assert env_devel_file.name == ".env-devel"
93+
# Loads and interpolates .env-devel file
9294
return load_dotenv(env_devel_file, verbose=True, interpolate=True)
9395

9496

97+
@pytest.fixture
98+
def env_devel_dict(_env_devel_dict_session: EnvVarsDict) -> EnvVarsDict:
99+
# NOTE: Returns a copy of the session scoped env_devel_dict on every
100+
# test run to avoid cross-test pollution.
101+
return deepcopy(_env_devel_dict_session)
102+
103+
95104
@pytest.fixture
96105
def mock_env_devel_environment(
97106
env_devel_dict: EnvVarsDict, monkeypatch: pytest.MonkeyPatch

services/catalog/tests/unit/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import hashlib
1010
from collections.abc import AsyncIterator, Awaitable, Callable, Iterator
11+
from copy import deepcopy
1112
from pathlib import Path
1213
from typing import Any, NamedTuple
1314

@@ -74,14 +75,14 @@ def package_dir() -> Path:
7475
return dirpath
7576

7677

77-
@pytest.fixture(scope="session")
78+
@pytest.fixture
7879
def env_devel_dict(
7980
env_devel_dict: EnvVarsDict, external_envfile_dict: EnvVarsDict
8081
) -> EnvVarsDict:
8182
if external_envfile_dict:
8283
assert "CATALOG_DEV_FEATURES_ENABLED" in external_envfile_dict
8384
assert "CATALOG_SERVICES_DEFAULT_RESOURCES" in external_envfile_dict
84-
return external_envfile_dict
85+
return deepcopy(external_envfile_dict)
8586
return env_devel_dict
8687

8788

services/efs-guardian/tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# pylint: disable=unused-variable
66

77

8+
from copy import deepcopy
89
from pathlib import Path
910

1011
import pytest
@@ -52,12 +53,12 @@ def installed_package_dir() -> Path:
5253
return dirpath
5354

5455

55-
@pytest.fixture(scope="session")
56+
@pytest.fixture
5657
def env_devel_dict(
5758
env_devel_dict: EnvVarsDict, external_envfile_dict: EnvVarsDict
5859
) -> EnvVarsDict:
5960
if external_envfile_dict:
60-
return external_envfile_dict
61+
return deepcopy(external_envfile_dict)
6162
return env_devel_dict
6263

6364

services/efs-guardian/tests/unit/test_process_messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async def test_process_msg(
6060
user_id=user_id,
6161
product_name=product_name,
6262
)
63-
json_str = model_instance.json()
63+
json_str = model_instance.model_dump_json()
6464
model_bytes = json_str.encode("utf-8")
6565

6666
_expected_project_node_states = [".data_assets", "home_user_workspace"]
@@ -104,7 +104,7 @@ async def test_process_msg__dir_not_exists(
104104
user_id=user_id,
105105
product_name=product_name,
106106
)
107-
json_str = model_instance.json()
107+
json_str = model_instance.model_dump_json()
108108
model_bytes = json_str.encode("utf-8")
109109

110110
result = await process_dynamic_service_running_message(app, data=model_bytes)

services/payments/tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# pylint: disable=unused-argument
55
# pylint: disable=unused-variable
66

7+
from copy import deepcopy
78
from pathlib import Path
89

910
import pytest
@@ -61,12 +62,12 @@ def external_envfile_dict(external_envfile_dict: EnvVarsDict) -> EnvVarsDict:
6162
return external_envfile_dict
6263

6364

64-
@pytest.fixture(scope="session")
65+
@pytest.fixture
6566
def env_devel_dict(
6667
env_devel_dict: EnvVarsDict, external_envfile_dict: EnvVarsDict
6768
) -> EnvVarsDict:
6869
if external_envfile_dict:
69-
return external_envfile_dict
70+
return deepcopy(external_envfile_dict)
7071
return env_devel_dict
7172

7273

services/web/server/tests/unit/isolated/test_tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def mock_webserver_service_environment(
1818
monkeypatch: pytest.MonkeyPatch, mock_webserver_service_environment: EnvVarsDict
1919
) -> EnvVarsDict:
2020
monkeypatch.delenv("WEBSERVER_TRACING")
21+
2122
return mock_webserver_service_environment | setenvs_from_dict(
2223
monkeypatch,
2324
{
@@ -27,7 +28,6 @@ def mock_webserver_service_environment(
2728
)
2829

2930

30-
@pytest.mark.skip(reason="Test fails almost always in CI pipelines")
3131
def test_middleware_restrictions_opentelemetry_is_second_middleware(
3232
mock_webserver_service_environment: EnvVarsDict,
3333
):

0 commit comments

Comments
 (0)