Skip to content

Commit 1238403

Browse files
committed
Exclude cirq packages when comparing distributions before and after notebook test
Cirq sources may be included in importlib.metadata.distributions. We exclude them from the check if pytest virtual environment changed.
1 parent ff54976 commit 1238403

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

dev_tools/notebooks/notebook_test.py

Lines changed: 12 additions & 2 deletions
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

0 commit comments

Comments
 (0)