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

Fix non-ignored test, check all tests are executed #4262

Merged
merged 8 commits into from
Nov 26, 2020
Merged
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
4 changes: 3 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ jobs:
--ignore=pymc3/tests/test_distributions_timeseries.py
--ignore=pymc3/tests/test_examples.py
--ignore=pymc3/tests/test_gp.py
--ignore=pymc3/tests/test_mixture.py
--ignore=pymc3/tests/test_parallel_sampling.py
--ignore=pymc3/tests/test_posteriors.py
--ignore=pymc3/tests/test_quadpotential.py
--ignore=pymc3/tests/test_random.py
--ignore=pymc3/tests/test_sampling.py
--ignore=pymc3/tests/test_shape_handling
--ignore=pymc3/tests/test_shape_handling.py
--ignore=pymc3/tests/test_shared.py
--ignore=pymc3/tests/test_smc.py
--ignore=pymc3/tests/test_updates.py
Expand All @@ -44,6 +45,7 @@ jobs:
- |
pymc3/tests/test_examples.py
pymc3/tests/test_gp.py
pymc3/tests/test_mixture.py
pymc3/tests/test_posteriors.py
pymc3/tests/test_quadpotential.py
- |
Expand Down
15 changes: 11 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ repos:
- repo: local
hooks:
- id: watermark
name: Check notebooks have watermark (see Jupyter style guide from PyMC3 Wiki)
types: [jupyter]
args: [--negate, --multiline]
entry: '%load_ext watermark.*%watermark -n -u -v -iv -w'
language: pygrep
args: [--negate, --multiline]
minimum_pre_commit_version: 2.8.0
name: Check notebooks have watermark (see Jupyter style guide from PyMC3 Wiki)
types: [jupyter]
- id: check-toc
entry: python scripts/check_toc_is_complete.py
language: python
name: Check all notebooks appear in table of contents
pass_filenames: false
types: [jupyter]
entry: python scripts/check_toc_is_complete.py
- id: check-no-tests-are-ignored
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the only new hook here, in the others I just sorted the keys

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call adding this hook 👍

entry: python scripts/check_all_tests_are_covered.py
files: ^\.github/workflows/pytest\.yml$
language: python
name: Check no tests are ignored
pass_filenames: false
24 changes: 24 additions & 0 deletions scripts/check_all_tests_are_covered.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
In .github/workflows/pytest.yml, tests are split between multiple jobs.

Here, we check that the jobs ignored by the first job actually end up getting
run by the other jobs.
This is intended to be used as a pre-commit hook, see `.pre-commit-config.yaml`.
You can run it manually with `pre-commit run check-no-tests-are-ignored --all`.
"""

from pathlib import Path

import re

if __name__ == "__main__":
pytest_ci_job = Path(".github") / "workflows/pytest.yml"
txt = pytest_ci_job.read_text()
ignored_tests = set(re.findall(r"(?<=--ignore=)(pymc3/tests.*\.py)", txt))
non_ignored_tests = set(re.findall(r"(?<!--ignore=)(pymc3/tests.*\.py)", txt))
assert (
ignored_tests <= non_ignored_tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: these are sets, so <= means "is a subset of"

), f"The following tests are ignored by the first job but not run by the others: {ignored_tests.difference(non_ignored_tests)}"
assert (
ignored_tests >= non_ignored_tests
), f"The following tests are run by multiple jobs: {non_ignored_tests.difference(ignored_tests)}"