Skip to content

Commit bf67f29

Browse files
authoredMay 16, 2024··
CI - deflake Isolated pytest Ubuntu (#6603)
Problem: `test_isolated_packages.py` is still flaky and can fail on parallel builds of a local `cirq_core` wheel. Solution: Use per-worker copy of the cirq-core sources so that parallel builds do not have conflicting build files. Follow-up to #6593
1 parent cf86dda commit bf67f29

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed
 

‎dev_tools/notebooks/isolated_notebook_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"papermill",
9797
"jupyter",
9898
# assumed to be part of colab
99-
"seaborn~=0.11.1",
99+
"seaborn~=0.12",
100100
]
101101

102102

‎dev_tools/notebooks/notebook_test.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import pytest
2727

2828
from dev_tools import shell_tools
29+
from dev_tools.modules import list_modules
2930
from dev_tools.notebooks import filter_notebooks, list_all_notebooks, rewrite_notebook
3031
from dev_tools.test_utils import only_on_posix
3132

@@ -63,9 +64,18 @@ def require_packages_not_changed():
6364
6465
Raise AssertionError if the pre-existing set of Python packages changes in any way.
6566
"""
66-
packages_before = set((d.name, d.version) for d in importlib.metadata.distributions())
67+
cirq_packages = set(m.name for m in list_modules()).union(["cirq"])
68+
packages_before = set(
69+
(d.name, d.version)
70+
for d in importlib.metadata.distributions()
71+
if d.name not in cirq_packages
72+
)
6773
yield
68-
packages_after = set((d.name, d.version) for d in importlib.metadata.distributions())
74+
packages_after = set(
75+
(d.name, d.version)
76+
for d in importlib.metadata.distributions()
77+
if d.name not in cirq_packages
78+
)
6979
assert packages_after == packages_before
7080

7181

‎dev_tools/packaging/isolated_packages_test.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,22 @@
3232
# the "isolation" fails and for example cirq-core would be on the PATH
3333
@mock.patch.dict(os.environ, {"PYTHONPATH": ""})
3434
@pytest.mark.parametrize('module', list_modules(), ids=[m.name for m in list_modules()])
35-
def test_isolated_packages(cloned_env, module):
35+
def test_isolated_packages(cloned_env, module, tmp_path):
3636
env = cloned_env("isolated_packages", *PACKAGES)
3737

3838
if str(module.root) != "cirq-core":
3939
assert f'cirq-core=={module.version}' in module.install_requires
4040

41+
# TODO: Remove after upgrading package builds from setup.py to PEP-517
42+
# Create per-worker copy of cirq-core sources so that parallel builds
43+
# of cirq-core wheel do not conflict.
44+
opt_cirq_core = (
45+
[str(shutil.copytree("./cirq-core", tmp_path / "cirq-core"))]
46+
if str(module.root) != "cirq-core"
47+
else []
48+
)
4149
result = shell_tools.run(
42-
f"{env}/bin/pip install --no-clean ./{module.root} ./cirq-core".split(),
50+
[f"{env}/bin/pip", "install", f"./{module.root}", *opt_cirq_core],
4351
stderr=subprocess.PIPE,
4452
check=False,
4553
)

‎dev_tools/requirements/deps/notebook.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ papermill~=2.3.2
1313
-r ../../../cirq-core/cirq/contrib/requirements.txt
1414

1515
# assumed to be part of colab
16-
seaborn~=0.11.1
16+
seaborn~=0.12

0 commit comments

Comments
 (0)
Please sign in to comment.