Skip to content
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

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

Merged
merged 1 commit into from
Feb 8, 2019
Merged

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

merged 1 commit into from
Feb 8, 2019

Conversation

asottile
Copy link
Member

@asottile asottile commented Feb 7, 2019

Resolves #4739

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Good work!

except Exception as e:
# See issue https://github.com/pytest-dev/pytest/issues/2169
msg = "{}: error raised while trying to determine id of parameter '{}' at position {}\n"
msg = msg.format(item.nodeid, argname, idx)
# we only append the exception type and message because on Python 2 reraise does nothing
msg += " {}: {}\n".format(type(e).__name__, e)
six.raise_from(ValueError(msg), e)
if s:
return ascii_escaped(s)
Copy link
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
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
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
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
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
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
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
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
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
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)

except Exception as e:
# See issue https://github.com/pytest-dev/pytest/issues/2169
msg = "{}: error raised while trying to determine id of parameter '{}' at position {}\n"
msg = msg.format(item.nodeid, argname, idx)
# we only append the exception type and message because on Python 2 reraise does nothing
msg += " {}: {}\n".format(type(e).__name__, e)
six.raise_from(ValueError(msg), e)
if s:
return ascii_escaped(s)
Copy link
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
Member

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

@asottile
Copy link
Member Author

asottile commented Feb 8, 2019

@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
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