diff --git a/tests/conftest.py b/tests/conftest.py index 5288aa1f..25e8281c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -64,7 +64,9 @@ def pytest_make_parametrize_id(config, val, argname): elif isinstance(val, nullcontext): optional_string = "does_not_raise()" - if isinstance(optional_string, str) and len(optional_string) > MAX_SIZE: - optional_string = optional_string[: MAX_SIZE - 3] + "+++" # Can't use dots with pytest + if isinstance(optional_string, str): + optional_string = optional_string.replace("\n", " ") + if len(optional_string) > MAX_SIZE: + optional_string = optional_string[: MAX_SIZE - 3] + "+++" # Can't use dots with pytest return optional_string diff --git a/tests/unit/aggregation/test_values.py b/tests/unit/aggregation/test_values.py index 67f24862..719be0c3 100644 --- a/tests/unit/aggregation/test_values.py +++ b/tests/unit/aggregation/test_values.py @@ -29,6 +29,7 @@ TrimmedMean, UPGrad, UPGradWeighting, + Weighting, ) J_base = tensor([[-4.0, 1.0, 1.0], [6.0, 1.0, 1.0]]) @@ -116,7 +117,7 @@ def test_aggregator_output(A: Aggregator, J: Tensor, expected_output: Tensor): @mark.parametrize(["W", "G", "expected_output"], WEIGHTING_PARAMETRIZATIONS) -def test_weighting_output(W: Aggregator, G: Tensor, expected_output: Tensor): +def test_weighting_output(W: Weighting, G: Tensor, expected_output: Tensor): """Test that the output values of a weighting are fixed (on cpu).""" assert_close(W(G), expected_output, rtol=0, atol=1e-4) diff --git a/tests/unit/autogram/test_engine.py b/tests/unit/autogram/test_engine.py index 00ae67b1..b96824ec 100644 --- a/tests/unit/autogram/test_engine.py +++ b/tests/unit/autogram/test_engine.py @@ -301,11 +301,13 @@ def test_compute_gramian_various_output_shapes( assert_close(autogram_gramian, expected_gramian, rtol=1e-4, atol=1e-5) -def _non_empty_subsets(elements: set) -> list[set]: +def _non_empty_subsets(S: set) -> list[list]: """ - Generates the list of subsets of the given set, excluding the empty set. + Generates the list of subsets of the given set, excluding the empty set. The sets are returned + in the form of sorted lists so that the order is always the same, to make the parametrization of + the test reproducible. """ - return [set(c) for r in range(1, len(elements) + 1) for c in combinations(elements, r)] + return [sorted(set(c)) for r in range(1, len(S) + 1) for c in combinations(S, r)] @mark.parametrize("gramian_module_names", _non_empty_subsets({"fc0", "fc1", "fc2", "fc3", "fc4"}))