Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test examples #136

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
python -m pip install -e .[dmet,ebcc] --user
- name: Run unit tests
run: |
python -m pip install pytest pytest-cov --user
python -m pip install pytest pytest-cov pytest-xdist pytest-timeout --user
python .github/workflows/run_tests.py
- name: Upload to codecov
uses: codecov/codecov-action@v3
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
args = [
"vayesta/tests",
"--cov=vayesta",
"-n=auto", # Multi-processing with pytest-xdist
"-s", # Show stdout output
]

if len(sys.argv) > 1 and sys.argv[1] == "--with-veryslow":
Expand Down
28 changes: 0 additions & 28 deletions examples/run_examples.py

This file was deleted.

32 changes: 32 additions & 0 deletions vayesta/tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys
from pathlib import Path
import importlib
from time import perf_counter

import pytest


example_path = Path(__file__).parent.parent.parent / 'examples'
examples_files = list(example_path.glob('**/*.py'))
timings = {}


@pytest.fixture(params=examples_files, ids=lambda x: '/'.join([x.parent.name, x.name]))
def example_file(request):
return request.param


@pytest.fixture(scope='module', autouse=True)
def report_timings() -> None:
yield
for name, time in timings.items():
print(f"Time for {name:20s}: {time:.1f} s")


@pytest.mark.timeout(300)
def test_example(example_file):
spec = importlib.util.spec_from_file_location(example_file.name, str(example_file))
example = importlib.util.module_from_spec(spec)
t_start = perf_counter()
spec.loader.exec_module(example)
timings['/'.join([example_file.parent.name, example_file.name])] = perf_counter() - t_start
Loading