-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
"Empty id" mechanism in callspec #8155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks @RonnyPfannschmidt ! Yes I totally agree with you for However the need arises with a from pytest_cases import parametrize, fixture, fixture_ref
@fixture
@parametrize("o", [1, 2])
def b(o):
pass
@parametrize("a", [0, 1, 2, fixture_ref(b)])
def test_foo(a):
pass In that example, you probably agree that a good list of id would be:
However, behind the scenes, I do a little optimization so I create a from pytest_cases import parametrize, fixture, fixture_ref
@fixture
@parametrize("o", [1, 2])
def b(o):
pass
@parametrize("a", [0, 1, 2, fixture_ref(b)], idstyle="explicit")
def test_foo(a):
pass yields
You can see that there are two hidden parameter controling the fixture union alternative "branch 1 = params 0:3" or "branch 2 = the fixture reference". With this id style we see explicit test ids So back to the ids of the first example above: in order to make them simple and straightforward, I need the "union alternative" parameter to completely disappear, not even remaining as a single dash. The best I can do without hack is:
So I had to hack to remove the useless dash. This is where a (Note: the above behaviour is in pytest-cases 3.0.0, about to be released) |
For reference: the discussion about various styles of ids: smarie/python-pytest-cases#154 (comment) |
That seems to me like the full parameterset with explicit ids would have to be generated in pytest-cases to support reasonably complete I'd control |
Hi dear
pytest
maintainers,I noticed that starting in pytest 5.4.0,
CallSpec2.id
does not automatically filter out ids that are empty strings from the ids list. So if in the ids list there is['a', '', 'b']
in old versions that would lead to id'a-b'
and now it leads to'a--b'
. I understand the rationale:pytest
should not hide anything from users, so if there is an empty string id somewhere, it should appear.Unfortunately I was relying on this undocumented mechanism in
pytest-cases
, because there is a specific situation with fixture unions induced by the new@parametrize
, in which I wish to remove a useless piece of id from a callspec. I found an ugly workaround: to use a very long and unique string constant as a marker for "id to remove" and then have a specific cleaning hook in the plugin removing such constants from callspec ids lists.I was wondering if there could be a better way for the future, baked in the pytest API. For example we could introduce an explicit
pytest.NO_ID
constant that would be filtered out inCallSpec2.id
.What do you think ? I can propose a PR if needed
The text was updated successfully, but these errors were encountered: