pytest.mark.parametrize with a dict is sharing mutable state between cases
pytest 8.1. I parametrize a test with a list of dicts: @pytest.mark.parametrize('cfg', [{'a': 1}, {'a': 2}]). Inside the test I mutate cfg['b'] = 3. It works for the first case but the second case sometimes sees 'b' already set. Are the parametrize values shared across test invocations? And if so, is it shared across separate pytest runs too? I only noticed because one specific pair of cases failed when the suite got reordered, which made it look like a random flake.
4 replies