Skip to content

Commit 35baea2

Browse files
Do not run tutorial tests by default (#668)
This turns off running tests of tutorials by default. Tutorial tests are run by calling `pytest --run-tutorials`. Testing of tutorials remains on in the GitHub action, currently for all pushes. --------- Co-authored-by: Theodore Turocy <ted.turocy@gmail.com>
1 parent 90060bc commit 35baea2

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

.github/workflows/python.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
cd dist
3333
pip install -v pygambit*.tar.gz
3434
- name: Run tests
35-
run: pytest
35+
run: pytest --run-tutorials
3636

3737
macos-13:
3838
runs-on: macos-13
@@ -52,7 +52,6 @@ jobs:
5252
python -m pip install --upgrade pip
5353
pip install setuptools build cython wheel
5454
pip install -r tests/requirements.txt
55-
pip install -r doc/requirements.txt
5655
- name: Build extension
5756
run: |
5857
python -m pip install -v .
@@ -82,7 +81,7 @@ jobs:
8281
run: |
8382
python -m pip install -v .
8483
- name: Run tests
85-
run: pytest
84+
run: pytest --run-tutorials
8685

8786
windows:
8887
runs-on: windows-latest
@@ -102,9 +101,9 @@ jobs:
102101
python -m pip install --upgrade pip
103102
pip install setuptools build cython wheel
104103
pip install -r tests/requirements.txt
105-
pip install nbformat nbclient ipykernel jupyter matplotlib
104+
pip install -r doc/requirements.txt
106105
- name: Build extension
107106
run: |
108107
python -m pip install -v .
109108
- name: Run tests
110-
run: pytest
109+
run: pytest --run-tutorials

doc/developer.contributing.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ You can also run the tests locally before submitting your pull request, using `p
9999

100100
pytest
101101

102+
3. [Optional] If you wish to run the tutorial notebook tests, you will need to add the ``--run-tutorials`` flag, which require the `doc` dependencies: ::
103+
104+
pip install -r doc/requirements.txt
105+
pytest --run-tutorials
106+
102107
Adding to the test suite
103108
^^^^^^^^^^^^^^^^^^^^^^^^
104109

doc/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ ipython
99
matplotlib
1010
pickleshare
1111
jupyter
12-
open_spiel
12+
open_spiel; sys_platform != 'win32'

tests/conftest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
3+
4+
def pytest_addoption(parser):
5+
parser.addoption(
6+
"--run-tutorials",
7+
action="store_true",
8+
default=False,
9+
help="Run tutorial notebook tests",
10+
)
11+
12+
13+
def pytest_configure(config):
14+
config.addinivalue_line(
15+
"markers", "tutorials: mark test as a tutorial notebook test"
16+
)
17+
18+
19+
def pytest_collection_modifyitems(config, items):
20+
if config.getoption("--run-tutorials"):
21+
# --run-tutorials given in cli: do not skip tutorial tests
22+
return
23+
24+
# Check if test_tutorials.py was explicitly specified
25+
args = config.invocation_params.args
26+
if any("test_tutorials.py" in str(arg) for arg in args):
27+
# test_tutorials.py explicitly run: do not skip
28+
return
29+
30+
skip_tutorials = pytest.mark.skip(reason="need --run-tutorials option to run")
31+
for item in items:
32+
if "tutorials" in item.keywords:
33+
item.add_marker(skip_tutorials)

tests/test_tutorials.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def _find_tutorial_notebooks():
3939
_NOTEBOOKS = _find_tutorial_notebooks()
4040

4141

42+
@pytest.mark.tutorials
4243
@pytest.mark.parametrize("nb_path", _NOTEBOOKS, ids=[p.name for p in _NOTEBOOKS])
4344
def test_execute_notebook(nb_path):
4445
"""Execute a single Jupyter notebook and fail if any cell errors occur.

0 commit comments

Comments
 (0)