forked from pybamm-team/PyBaMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
38 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--examples", action="store_true", default=False, help="run examples tests" | ||
) | ||
|
||
|
||
def pytest_configure(config): | ||
config.addinivalue_line("markers", "examples: mark test as an example") | ||
|
||
|
||
def pytest_collection_modifyitems(config, items): | ||
options = { | ||
"examples": "examples", | ||
} | ||
selected_markers = [ | ||
marker for option, marker in options.items() if config.getoption(option) | ||
] | ||
if "examples" not in selected_markers: | ||
skip_example = pytest.mark.skip(reason="Skipping example tests since --examples option is not provided") | ||
for item in items: | ||
if 'examples' in item.keywords: | ||
item.add_marker(skip_example) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,24 @@ | ||
import os | ||
import runpy | ||
|
||
from pathlib import Path | ||
import pytest | ||
|
||
ROOT_DIR = Path(os.path.join( | ||
os.path.dirname(__file__), "..")) | ||
|
||
|
||
class TestExamples: | ||
""" | ||
A class to test the example scripts. | ||
""" | ||
|
||
def list_of_files(): | ||
file_list = [] | ||
base_dir = os.path.join( | ||
os.path.dirname(__file__), "..", "examples", "scripts" | ||
) | ||
for root, _, files in os.walk(base_dir): | ||
for file in files: | ||
if file.endswith(".py"): | ||
file_list.append(os.path.join(root, file)) | ||
base_dir = ROOT_DIR.joinpath("examples", "scripts") | ||
# Recursively find all python files inside examples/scripts | ||
file_list = list(base_dir.rglob('*.py')) | ||
return file_list | ||
|
||
|
||
|
||
@pytest.mark.parametrize("files", list_of_files()) | ||
@pytest.mark.examples | ||
def test_example_scripts(self, files): | ||
runpy.run_path(files) | ||
|