Skip to content

Commit 31bf1ac

Browse files
Add weekly CI workflow to test all notebooks (#6046)
* Add a test to run all notebooks * Add a Weekly CI workflow to run all notebooks test * Temporarily increase cadence to daily runs for validation
1 parent ae62250 commit 31bf1ac

File tree

3 files changed

+83
-21
lines changed

3 files changed

+83
-21
lines changed

Diff for: .github/workflows/ci-weekly.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Continuous Integration - Weekly
2+
3+
on:
4+
schedule:
5+
# Checks out master by default.
6+
# TODO (#6037) - replace with weekly cadence after verification
7+
- cron: '0 0 * * *'
8+
# - cron: '0 0 * * 0'
9+
10+
concurrency:
11+
group: ${{ github.workflow }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
notebooks-stable:
16+
name: All Notebooks Isolated Test against Cirq stable
17+
env:
18+
NOTEBOOK_PARTITIONS: 4
19+
strategy:
20+
matrix:
21+
# partitions should be named partition-0 to partition-(NOTEBOOK_PARTITIONS-1)
22+
partition: [partition-0, partition-1, partition-2, partition-3]
23+
runs-on: ubuntu-20.04
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: actions/setup-python@v1
27+
with:
28+
python-version: '3.8'
29+
architecture: 'x64'
30+
- name: Install requirements
31+
run: pip install -r dev_tools/requirements/isolated-base.env.txt
32+
- name: Notebook tests
33+
run: check/pytest -n auto -m weekly dev_tools/notebooks/isolated_notebook_test.py -k ${{matrix.partition}}
34+
- uses: actions/upload-artifact@v2
35+
if: failure()
36+
with:
37+
name: notebook-outputs
38+
path: out

Diff for: dev_tools/conftest.py

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
def pytest_configure(config):
3030
config.addinivalue_line("markers", "slow: mark tests as slow")
31+
config.addinivalue_line("markers", "weekly: mark tests as run only by weekly automation")
3132

3233

3334
def pytest_collection_modifyitems(config, items):
@@ -40,6 +41,11 @@ def pytest_collection_modifyitems(config, items):
4041
if 'slow' in item.keywords:
4142
item.add_marker(skip_slow_marker)
4243

44+
skip_weekly_marker = pytest.mark.skip(reason='only run by weekly automation')
45+
for item in items:
46+
if 'weekly' in item.keywords:
47+
item.add_marker(skip_weekly_marker)
48+
4349

4450
@pytest.fixture(scope="session")
4551
def cloned_env(testrun_uid, worker_id):

Diff for: dev_tools/notebooks/isolated_notebook_test.py

+39-21
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
# ========================== ISOLATED NOTEBOOK TESTS ============================================
1616
#
17-
# In these tests are only changed notebooks are tested. It is assumed that notebooks install cirq
18-
# conditionally if they can't import cirq. This installation path is the main focus and it is
19-
# exercised in an isolated virtual environment for each notebook. This is also the path that is
20-
# tested in the devsite workflows, these tests meant to provide earlier feedback.
17+
# It is assumed that notebooks install cirq conditionally if they can't import cirq. This
18+
# installation path is the main focus and it is exercised in an isolated virtual environment for
19+
# each notebook. This is also the path that is tested in the devsite workflows, these tests meant
20+
# to provide earlier feedback.
2121
#
2222
# In case the dev environment changes or this particular file changes, all notebooks are executed!
2323
# This can take a long time and even lead to timeout on Github Actions, hence partitioning of the
@@ -155,23 +155,7 @@ def _partitioned_test_cases(notebooks):
155155
return [(f"partition-{i%n_partitions}", notebook) for i, notebook in enumerate(notebooks)]
156156

157157

158-
@pytest.mark.slow
159-
@pytest.mark.parametrize(
160-
"partition, notebook_path",
161-
_partitioned_test_cases(filter_notebooks(_list_changed_notebooks(), SKIP_NOTEBOOKS)),
162-
)
163-
def test_notebooks_against_released_cirq(partition, notebook_path, cloned_env):
164-
"""Tests the notebooks in isolated virtual environments.
165-
166-
In order to speed up the execution of these tests an auxiliary file may be supplied which
167-
performs substitutions on the notebook to make it faster.
168-
169-
Specifically for a notebook file notebook.ipynb, one can supply a file notebook.tst which
170-
contains the substitutes. The substitutions are provide in the form `pattern->replacement`
171-
where the pattern is what is matched and replaced. While the pattern is compiled as a
172-
regular expression, it is considered best practice to not use complicated regular expressions.
173-
Lines in this file that do not have `->` are ignored.
174-
"""
158+
def _rewrite_and_run_notebook(notebook_path, cloned_env):
175159
notebook_file = os.path.basename(notebook_path)
176160
notebook_rel_dir = os.path.dirname(os.path.relpath(notebook_path, "."))
177161
out_path = f"out/{notebook_rel_dir}/{notebook_file[:-6]}.out.ipynb"
@@ -213,6 +197,40 @@ def test_notebooks_against_released_cirq(partition, notebook_path, cloned_env):
213197
os.remove(rewritten_notebook_path)
214198

215199

200+
@pytest.mark.slow
201+
@pytest.mark.parametrize(
202+
"partition, notebook_path",
203+
_partitioned_test_cases(filter_notebooks(_list_changed_notebooks(), SKIP_NOTEBOOKS)),
204+
)
205+
def test_changed_notebooks_against_released_cirq(partition, notebook_path, cloned_env):
206+
"""Tests changed notebooks in isolated virtual environments.
207+
208+
In order to speed up the execution of these tests an auxiliary file may be supplied which
209+
performs substitutions on the notebook to make it faster.
210+
211+
Specifically for a notebook file notebook.ipynb, one can supply a file notebook.tst which
212+
contains the substitutes. The substitutions are provide in the form `pattern->replacement`
213+
where the pattern is what is matched and replaced. While the pattern is compiled as a
214+
regular expression, it is considered best practice to not use complicated regular expressions.
215+
Lines in this file that do not have `->` are ignored.
216+
"""
217+
_rewrite_and_run_notebook(notebook_path, cloned_env)
218+
219+
220+
@pytest.mark.weekly
221+
@pytest.mark.parametrize(
222+
"partition, notebook_path",
223+
_partitioned_test_cases(filter_notebooks(list_all_notebooks(), SKIP_NOTEBOOKS)),
224+
)
225+
def test_all_notebooks_against_released_cirq(partition, notebook_path, cloned_env):
226+
"""Tests all notebooks in isolated virtual environments.
227+
228+
See `test_changed_notebooks_against_released_cirq` for more details on
229+
notebooks execution.
230+
"""
231+
_rewrite_and_run_notebook(notebook_path, cloned_env)
232+
233+
216234
@pytest.mark.parametrize("notebook_path", NOTEBOOKS_DEPENDING_ON_UNRELEASED_FEATURES)
217235
def test_ensure_unreleased_notebooks_install_cirq_pre(notebook_path):
218236
# utf-8 is important for Windows testing, otherwise characters like ┌──┐ fail on cp1252

0 commit comments

Comments
 (0)