Skip to content

Fix parametrize(... ids=<function>) when the function returns non-strings#4740

Merged
asottile merged 1 commit into
pytest-dev:masterfrom
asottile:bugfix_4739
Feb 8, 2019
Merged

Fix parametrize(... ids=<function>) when the function returns non-strings#4740
asottile merged 1 commit into
pytest-dev:masterfrom
asottile:bugfix_4739

Conversation

@asottile

@asottile asottile commented Feb 7, 2019

Copy link
Copy Markdown
Member

Resolves #4739

@nicoddemus nicoddemus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!

Comment thread src/_pytest/python.py
msg += " {}: {}\n".format(type(e).__name__, e)
six.raise_from(ValueError(msg), e)
if s:
return ascii_escaped(s)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a behavior change, the hook now can override the given id
additionally i noted we font factor in the ascii_escape of the id from the hook

i propose factoring out the escaping logic to a function that gets a fallback result and using that to wrap around the return value in the different cases

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headscratch I'm not seeing the behaviour change -- can you shed some light? The only behaviour I intended to change is crash -> not crash (and restore what happened in pytest 3.0.7)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by moving the idfn handling from returning before the pytest_make_parametrize_id to after invoking it,
the behavior is accidentally changed, as now the hook can override the result of the idfn, while before it couldn't

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like an improvement, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as done here its possible that this inadvertely changes ids in a testsuite, so its a change for a major release

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems broken though that in this weird special case we don't apply the hook

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is broken, its just that bugfixing is a breaking behavioral change

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how if fixing any bug not a behavioural change 🤣

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RonnyPfannschmidt better now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems much better, my gut is not 100% happy with the solution we have tho,
i'd really like to note down to change the behavior for pytest 6.0 (avoiding it in 5.0 for the management of the pytohn support drop)

Comment thread src/_pytest/python.py
msg += " {}: {}\n".format(type(e).__name__, e)
six.raise_from(ValueError(msg), e)
if s:
return ascii_escaped(s)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems much better, my gut is not 100% happy with the solution we have tho,
i'd really like to note down to change the behavior for pytest 6.0 (avoiding it in 5.0 for the management of the pytohn support drop)

@asottile asottile merged commit ea73246 into pytest-dev:master Feb 8, 2019
@asottile asottile deleted the bugfix_4739 branch February 8, 2019 05:47
@RonnyPfannschmidt

Copy link
Copy Markdown
Member

@asottile would you like to create the followup issue, otherwise i will

@asottile

asottile commented Feb 8, 2019

Copy link
Copy Markdown
Member Author

@asottile would you like to create the followup issue, otherwise i will

I think you'll do it better justice than I will 👍

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

thanks, i'm on it then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants