Is it possible to assign an idfn after stacked parameterization? #6185
Labels
topic: fixtures
anything involving fixtures directly or indirectly
topic: parametrize
related to @pytest.mark.parametrize
type: proposal
proposal for a new feature, often to gather opinions or design the API around the new feature
pip list
from the virtual environment you are usingDescription
Brief
I am trying to provide
pytest
aidfn
after it has generated a large combinatorial dataset via modular parametrized fixtures.Context
pytest.mark.parametrize
is really useful for quickly generating multiple sets of data for a particular test. It's particularly great when stacked to generate all combinations of multiple parametrized arguments.pytest
provides a mechanism for automatically generating a test id from the params based on whether the param is primitive/non-primitive. It also allows the user to provide anidfn
so that the test input can be expressed in a way more relevant to the problem domain.@pytest.fixture
is allowed to be parametrized viaparams
. It is also modular and can use other fixtures, which in turn can be parametrized, but it need not be aware of that.Using the above 3 properties of
pytest
, I am able to pass in a single fixture to a test function that uses two other parametrized fixtures, and converts their raw values into anamedtuple
that better reflects the problem domain.However, I am more interested in the composite data produced by the single fixture than the primitive data it acquires from the other fixtures, and would like to reflect this in the output of
pytest
.I have tried:
idfn
to@pytest.fixture(ids=
idfn
to@pytest.mark.parametrize(..., ids=
pytest_make_parametrize_id
inconftest.py
all without success.
pip list
versions
Example
Output
Desired Output
Quickfix
For this small scenario it's possible to write something along the lines:
Which will achieve the desired output, but at the cost of easily extending the tests.
Flaws in the regex could quickly be found with test params:
-
c_define.name = "foo_bar"
-
c_define.value = "0xF"
-
c_define.string = "#define{space}{space}foo{space}{space}1"
And it would be much easier to append these instances to a
pytest.mark.parametrize
list.The text was updated successfully, but these errors were encountered: