test(create): refactor and parametrize class-based dataset tests#597
Conversation
|
In order to verify no tests are lost, please do the following: $ git clone https://github.com/ecmwf/anemoi-datasets.git
$ cd anemoi-datasets
$ git checkout -b jfrazier/parametrize-test-classes 9ba8096041690a2543f40f434674bfb1096cad95
$ git worktree add worktree_main 8e54420c20af9554121ae03fc556e7022864b8f7
$ python -m venv .venv
$ uv pip install .[all,tests]
$ . .venv/bin/activate Then run the below script (if you get an #!/usr/bin/bash
# @brief Extract passed/skipped tests from pytest of main and pytest of PR to verify no tests lost
set -eu
# Run pytest on main
pytest_main_log=/tmp/pytest_main.log
[[ ! -f ${pytest_main_log} ]] && pytest -v worktree_main/tests/create/test_classes.py | tee ${pytest_main_log}
pytest_main_PASSED=($(grep "PASSED" ${pytest_main_log} | grep -o "gridd.*" | sort -u))
pytest_main_SKIPPED=($(grep "SKIPPED" ${pytest_main_log} | grep -o "gridd.*" | sort -u))
# Run pytest on PR
pytest_pr_log=/tmp/pytest_pr.log
[[ ! -f ${pytest_pr_log} ]] && pytest -v tests/create/test_classes.py | tee ${pytest_pr_log}
pytest_pr_PASSED=($(grep "PASSED" ${pytest_pr_log} | grep -o "gridd.*" | sort -u))
pytest_pr_SKIPPED=($(grep "SKIPPED" ${pytest_pr_log} | grep -o "gridded.*" | sort -u))
# Print PASSED side by side
n_pr_PASSED="${#pytest_pr_PASSED[@]}"
n_main_PASSED="${#pytest_main_PASSED[@]}"
[[ ! ${n_pr_PASSED} -eq ${n_main_PASSED} ]] && echo "assert eq" && exit 1
echo "----------"
echo " PASSED"
echo "main ----> PR"
echo "----------"
for (( i = 0; i < n_pr_PASSED; i++))
do
echo "${pytest_main_PASSED[$i]} ---> ${pytest_pr_PASSED[$i]}"
done
echo
# Print SKIPPED side by side
n_pr_SKIPPED="${#pytest_pr_SKIPPED[@]}"
n_main_SKIPPED="${#pytest_main_SKIPPED[@]}"
[[ ! ${n_pr_SKIPPED} -eq ${n_main_SKIPPED} ]] && echo "assert eq" && exit 1
echo "-----------"
echo " SKIPPED"
echo "main -----> PR"
echo "-----------"
for (( i = 0; i < n_pr_SKIPPED; i++))
do
echo "${pytest_main_SKIPPED[$i]} ---> ${pytest_pr_SKIPPED[$i]}"
donewhich outputs the names of original tests on main mapped to the name of the test auto-generated by parametrize. Due to the sorting, the The script does pytest twice, however you could simply put the logs below into the |
64ebf0b to
8b90e43
Compare
|
I think I see why this is failing in the CI. Tests pass locally for me as well. Maybe related to this? i.e.,
|
|
I guess it was an unrelated problem, see #609 |
Description
Simplifies and parametrizes redundant testing code in
/tests/create/test_classes.pyFollows parametrization conventions of existing tests:
What problem does this change solve?
Improve extensibility of class-based dataset tests.
Additional notes
To verify this doesn't remove any existing tests, please see #597 (comment)
As a contributor to the Anemoi framework, please ensure that your changes include unit tests, updates to any affected dependencies and documentation, and have been tested in a parallel setting (i.e., with multiple GPUs). As a reviewer, you are also responsible for verifying these aspects and requesting changes if they are not adequately addressed. For guidelines about those please refer to https://anemoi.readthedocs.io/en/latest/
By opening this pull request, I affirm that all authors agree to the Contributor License Agreement.