Skip to content

Commit 2301682

Browse files
authored
[ML][Pipelines] Fix flaky tests in live mode (Azure#27498)
* test: not use pytest.tmp_path to avoid flaky test during ci * test: wait for more seconds to avoid flaky test
1 parent 5fd4e9d commit 2301682

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

sdk/ml/azure-ai-ml/tests/component/e2etests/test_component.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import tempfile
23
import uuid
34
from itertools import tee
45
from pathlib import Path
@@ -374,13 +375,15 @@ def test_component_update(self, client: MLClient, randstr: Callable[[str], str])
374375
@pytest.mark.disable_mock_code_hash
375376
@pytest.mark.skipif(condition=not is_live(), reason="reuse test, target to verify service-side behavior")
376377
def test_component_create_twice_same_code_arm_id(
377-
self, client: MLClient, randstr: Callable[[str], str], tmp_path: Path
378+
self, client: MLClient, randstr: Callable[[str], str]
378379
) -> None:
379-
component_name = randstr("component_name")
380-
# create new component to prevent the issue when same component code got created at the same time
381-
component_path = tmp_path / "component.yml"
382-
component_path.write_text(
383-
f"""
380+
with tempfile.TemporaryDirectory() as tmp_path:
381+
tmp_path = Path(tmp_path)
382+
component_name = randstr("component_name")
383+
# create new component to prevent the issue when same component code got created at the same time
384+
component_path = tmp_path / "component.yml"
385+
component_path.write_text(
386+
f"""
384387
$schema: https://azuremlschemas.azureedge.net/development/commandComponent.schema.json
385388
name: {component_name}
386389
version: 1
@@ -389,13 +392,13 @@ def test_component_create_twice_same_code_arm_id(
389392
command: echo Hello World
390393
code: "."
391394
environment: azureml:AzureML-sklearn-0.24-ubuntu18.04-py37-cpu:1"""
392-
)
393-
# create a component
394-
component_resource1 = create_component(client, component_name, path=component_path)
395-
# create again
396-
component_resource2 = create_component(client, component_name, path=component_path)
397-
# the code arm id should be the same
398-
assert component_resource1.code == component_resource2.code
395+
)
396+
# create a component
397+
component_resource1 = create_component(client, component_name, path=component_path)
398+
# create again
399+
component_resource2 = create_component(client, component_name, path=component_path)
400+
# the code arm id should be the same
401+
assert component_resource1.code == component_resource2.code
399402

400403
@pytest.mark.skipif(condition=not is_live(), reason="non-deterministic upload fails in playback on CI")
401404
def test_component_update_code(self, client: MLClient, randstr: Callable[[str], str], tmp_path: Path) -> None:
@@ -622,7 +625,7 @@ def test_command_component_get_latest_label(self, client: MLClient, randstr: Cal
622625

623626
for version in versions:
624627
create_component(client, name, params_override=[{"version": version}])
625-
sleep_if_live(1)
628+
sleep_if_live(5)
626629
assert client.components.get(name, label="latest").version == version
627630

628631
@pytest.mark.skip(reason="Test fails because MFE index service consistency bug")

0 commit comments

Comments
 (0)