@@ -52,3 +52,30 @@ In this example, both `test_b[7]` and `test_c[7]` are skipped, because
52
52
`test_a[7] ` deliberately fails.
53
53
54
54
.. __ : https://docs.pytest.org/en/latest/fixture.html#automatic-grouping-of-tests-by-fixture-instances
55
+
56
+ Depend on all instances of a parametrized test at once
57
+ ------------------------------------------------------
58
+
59
+ If a test depends on a all instances of a parametrized test at once,
60
+ listing all of them in the :func: `pytest.mark.dependency ` marker
61
+ explicitly might not be the best solution. But you can dynamically
62
+ compile these lists from the parameter values, as in the following
63
+ example:
64
+
65
+ .. literalinclude :: ../examples/all_params.py
66
+
67
+ Here, `test_b `, `test_d `, and `test_f ` will be skipped because they
68
+ depend on all instances of `test_a `, `test_c `, and `test_e `
69
+ respectively, but `test_a[13] `, `test_c[6-5] `, and `test_e[def] ` fail.
70
+ The list of the test instances is compiled in the helper function
71
+ `instances() `.
72
+
73
+ Unfortunately you need knowledge how pytest encodes parameter values
74
+ in test instance names to write this helper function. Note in
75
+ particular how lists of parameter values are compiled into one single
76
+ string in the case of multi parameter tests. But also note that this
77
+ example of the `instances() ` helper will only work for simple cases.
78
+ It requires the parameter values to be scalars that can easily be
79
+ converted to strings. And it will fail if the same list of parameters
80
+ is passed to the same test more then once, because then, pytest will
81
+ add an index to the name to disambiguate the parameter values.
0 commit comments