Skip to content

Commit d495c8d

Browse files
mrmundtblnichosufikaur
authored
Turn on test_*.py for examples in integration test (#1679)
Co-authored-by: Bethany Nicholson <[email protected]> Co-authored-by: Sufi Kaur <[email protected]>
1 parent 0ca2acb commit d495c8d

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

.github/actions/run-examples/action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ inputs:
3131
required: false
3232
default: ''
3333

34+
run-notebooks:
35+
description: "Run notebook tests (via nbmake)"
36+
required: false
37+
default: 'true'
38+
39+
run-pyfiles:
40+
description: "Run Python *.py tests (test_*.py, *_test.py)"
41+
required: false
42+
default: 'true'
43+
3444
runs:
3545
using: composite
3646
steps:
@@ -63,6 +73,8 @@ runs:
6373
shell: bash -l {0}
6474
env:
6575
PYTHONPATH: ${{ github.action_path }}
76+
EXAMPLES_RUN_NOTEBOOKS: ${{ inputs.run-notebooks }}
77+
EXAMPLES_RUN_PYFILES: ${{ inputs.run-pyfiles }}
6678
PYTEST_ADDOPTS: >-
6779
--color=yes
6880
--durations=0

.github/actions/run-examples/examples_for_idaes_ci.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"""
44

55
from contextlib import contextmanager
6-
from dataclasses import dataclass, field
76
import fnmatch
8-
import logging
97
import os
108
from pathlib import Path
119
import sys
@@ -21,6 +19,12 @@
2119
matchmarker = pytest.StashKey()
2220
marked = pytest.StashKey()
2321

22+
# Environment triggers for use either locally
23+
# or in GitHub Action
24+
_ENV_TRUE = {"1", "true", "yes", "on"}
25+
RUN_NOTEBOOKS = str(os.getenv("EXAMPLES_RUN_NOTEBOOKS", "1")).lower() in _ENV_TRUE
26+
RUN_PYFILES = str(os.getenv("EXAMPLES_RUN_PYFILES", "1")).lower() in _ENV_TRUE
27+
2428

2529
def _matches_pattern(item: pytest.Item, pattern: str) -> bool:
2630
to_match = os.fspath(item.path)
@@ -44,16 +48,31 @@ def pytest_sessionstart(session: pytest.Session):
4448

4549

4650
def pytest_ignore_collect(collection_path: Path, config: pytest.Config):
51+
"""Control what gets collected. By default, notebooks and tests; ignore other files."""
4752
if "_dev" in collection_path.parts:
4853
return True
4954
if not collection_path.is_file():
5055
return
51-
if collection_path.suffix == ".py":
52-
# specifically ignore python files
53-
return True
54-
if not collection_path.match("**/*_test.ipynb"):
56+
57+
suffix = collection_path.suffix
58+
# Notebook tests (only *_test.ipynb)
59+
if suffix == ".ipynb":
60+
if not RUN_NOTEBOOKS:
61+
return True
62+
return not collection_path.match("**/*_test.ipynb")
63+
64+
# Python tests (only test_*.py or *_test.py)
65+
if suffix == ".py":
66+
if not RUN_PYFILES:
67+
return True
68+
name = collection_path.name
69+
if fnmatch.fnmatch(name, "test_*.py") or fnmatch.fnmatch(name, "*_test.py"):
70+
return False
5571
return True
5672

73+
# Ignore everything else
74+
return True
75+
5776

5877
def pytest_collection_modifyitems(config: pytest.Config, items):
5978
for item in items:
@@ -102,7 +121,7 @@ def run_pytest(
102121
empty_file_for_ignoring.write_text("")
103122
args += ["-c", empty_file_for_ignoring]
104123

105-
with _temp_cwd(rootdir) as p:
124+
with _temp_cwd(rootdir):
106125
res = pytest.main(
107126
args,
108127
**kwargs,
@@ -114,6 +133,7 @@ def run_pytest(
114133
def main(args):
115134
rootdir = Path(idaes_examples.__path__[0])
116135

136+
# Always include --nbmake, but notebook collection can be disabled by env
117137
res = run_pytest(
118138
rootdir,
119139
[

0 commit comments

Comments
 (0)