Skip to content

Commit 14b3382

Browse files
authored
CI - deflake "Isolated pytest Ubuntu" (#7806)
Problem: The CI test "Isolated pytest Ubuntu" may still fail when cirq-core in the repository is copied with intermediate build files. Solution: Use a dedicated copy of cirq-core sources for installation in each module test including when testing cirq-core itself. Also use `logging` instead of `print` in the `cloned_env` fixture as `logging.info` is easier to recover from parallel pytest runs (run pytest with the `--log-level=info` option). Follow-up to #6603
1 parent 1467a32 commit 14b3382

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

dev_tools/conftest.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from __future__ import annotations
1616

17+
import logging
1718
import os
1819
import shutil
1920
import sys
@@ -28,6 +29,8 @@
2829
from dev_tools import shell_tools
2930
from dev_tools.env_tools import create_virtual_env
3031

32+
_LOGGER = logging.getLogger(__name__)
33+
3134

3235
@pytest.fixture(scope="session", autouse=True)
3336
def disable_local_gcloud_credentials(tmp_path_factory):
@@ -81,9 +84,13 @@ def base_env_creator(env_dir_name: str, *pip_install_args: str) -> Path:
8184
base_dir = base_temp_path / env_dir_name
8285
with FileLock(str(base_dir) + ".lock"):
8386
if _check_for_reuse_or_recreate(base_dir):
84-
print(f"Pytest worker [{worker_id}] is reusing {base_dir} for '{env_dir_name}'.")
87+
_LOGGER.info(
88+
f"Pytest worker [{worker_id}] is reusing {base_dir} for '{env_dir_name}'."
89+
)
8590
else:
86-
print(f"Pytest worker [{worker_id}] is creating {base_dir} for '{env_dir_name}'.")
91+
_LOGGER.info(
92+
f"Pytest worker [{worker_id}] is creating {base_dir} for '{env_dir_name}'."
93+
)
8794
_create_base_env(base_dir, pip_install_args)
8895

8996
clone_dir = base_temp_path / str(uuid.uuid4())
@@ -112,7 +119,7 @@ def _create_base_env(base_dir: Path, pip_install_args: tuple[str, ...]):
112119
except BaseException as ex:
113120
# cleanup on failure
114121
if base_dir.is_dir():
115-
print(f"Removing {base_dir}, due to error: {ex}")
122+
_LOGGER.info(f"Removing {base_dir}, due to error: {ex}")
116123
shutil.rmtree(base_dir)
117124
raise
118125

dev_tools/packaging/isolated_packages_test.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,16 @@
3737
def test_isolated_packages(cloned_env, module, tmp_path) -> None:
3838
env = cloned_env("isolated_packages", *PACKAGES)
3939

40-
if str(module.root) != "cirq-core":
40+
if module.name != "cirq-core":
4141
assert f'cirq-core=={module.version}' in module.install_requires
4242

43-
# TODO: Remove after upgrading package builds from setup.py to PEP-517
4443
# Create per-worker copy of cirq-core sources so that parallel builds
4544
# of cirq-core wheel do not conflict.
46-
opt_cirq_core = (
47-
[str(shutil.copytree("./cirq-core", tmp_path / "cirq-core"))]
48-
if str(module.root) != "cirq-core"
49-
else []
50-
)
45+
cirq_core_copy = shutil.copytree("./cirq-core", tmp_path / "cirq-core")
46+
# avoid specifying cirq-core twice
47+
opt_module_dir = [] if module.name == "cirq-core" else [f"./{module.root}"]
5148
result = shell_tools.run(
52-
[f"{env}/bin/pip", "install", f"./{module.root}", *opt_cirq_core],
49+
[f"{env}/bin/pip", "install", cirq_core_copy, *opt_module_dir],
5350
stderr=subprocess.PIPE,
5451
check=False,
5552
)

0 commit comments

Comments
 (0)