'Specifying CLI args only for individual Pytest parameters

I have a Pytest suite that takes advantage of fixture parametrization to run the entire test suite over a list of "test configurations". I have a few custom CLI options that you can specify when running the test suite in "non-parametrized mode". When running the tests in "parametrized mode" (which is triggered by another CLI option), I have some logic that essentially generates the test parameters based on configuration, and this configuration more-or-less maps to the CLI options you can specify when running in non-parametrized mode.

This is all working, and each mode works great on its own. You can do an individual non-parametrized run by specifying whatever CLI options you want, or you can do a parametrized run by specifying a different option, and it automatically configures all the right options values for each parameter.

But I'm trying to figure out how to sort of bridge the gap between these two modes, and allow individual options to be overridden when doing a parametrized run. Say my CLI options are --foo and --bar, which you can just manually specify if you want to do a non-parametrized run. But when doing a parametrized run, it generates a list of parameters which represent test configuration: say test_id_1 sets foo=1 and bar=a, and test_id_2 sets foo=2 and bar=b. I want to be able to do a parametrized run, but for test_id_2, override the value of foo to 42.

I've done enough research to be pretty confident that there isn't a nice simple out-of-the-box way of doing this, but has anyone done something similar or has any suggestions? The solution that comes to mind is just having some --options-override parameter with some special syntax for overriding parameters, like --options-override "test_id_1:foo=4,bar=d;test_id_2:foo=9,bar=z". This seems like it would work and shouldn't be too hard to implement, it's just a little messy (but maybe that's unavoidable?), and I'm curious whether something like this is already implemented in a plugin or something.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source