Skip to content

test: Fix some test parametrizations#576

Merged
ValerianRey merged 3 commits intomainfrom
fix-tests
Feb 18, 2026
Merged

test: Fix some test parametrizations#576
ValerianRey merged 3 commits intomainfrom
fix-tests

Conversation

@ValerianRey
Copy link
Contributor

Some test parametrization had problems, which we didn't see until we started using VSCode's testing tool, that runs each test by providing its exact parametrization string to pytest. For context, the parametrization string is called the id in the context of pytest, and it can be overridden in the pytest_make_parametrize_id function of conftest.py (which I did a few months ago to make them shorter and more informative).

There were two issues:

  • Some objects had a \n in their id. We didn't define the repr method for Weightings yet, so their repr was the method repr inheritted from nn.Module, which contains a \n. I fixed pytest_make_parametrize_id to replace \n by a space.
  • Some parametrizations were not deterministic. The output of _non_empty_subsets, used to make the parametrization of test_compute_partial_gramian in test_engine.py, was a list of sets. Since the order of set elements is non-deterministic, VSCode tried to call those tests with a given string (e.g. '{"fc0", "fc1"}), while the collection of pytest created a different possible parametrization (e.g. '{"fc1", "fc0"}'). I fixed this by making _non_empty_subsets return lists instead of sets, and explaining why in the docstring.

This also fixes a wrong type hint in test_weighting_output. I think ty cannot detect typing error in pytest's test parametrizations. I don't think there's an easy fix, unless we install some plugin.

This happens for Weightings, for which we didn't provide a proper repr
and str yet. So this fixes test_weighting_output in test_values.py.
@ValerianRey ValerianRey added the cc: test Conventional commit type for changes to tests. label Feb 18, 2026
@ValerianRey ValerianRey self-assigned this Feb 18, 2026
@ValerianRey ValerianRey added the cc: test Conventional commit type for changes to tests. label Feb 18, 2026
@ValerianRey
Copy link
Contributor Author

@PierreQuinton FYI, it's now possible to run all tests from VSCode from the testing tab.

@ValerianRey ValerianRey merged commit 3ff9a8b into main Feb 18, 2026
15 checks passed
@ValerianRey ValerianRey deleted the fix-tests branch February 18, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cc: test Conventional commit type for changes to tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments