No longer silently ignore errors in parametrize callable ids#2167
Conversation
b699476 to
51912f9
Compare
nicoddemus
left a comment
There was a problem hiding this comment.
Also, please rebase your PR on the features branch. This is a behavior change (for the better IMO), but even so should not be made in a bug-fix release.
| @@ -300,14 +300,35 @@ def test_idmaker_idfn_exception(self): | |||
| def ids(val): | |||
| raise Exception("bad code") | |||
There was a problem hiding this comment.
Probably better to raise a more unique exception here, like ValueError("error on ids") and catch that in pytest.raises below, also checking that is the same message.
Otherwise in the future someone might refactor this and then another exception is raised and this test won't catch it.
|
As far as I can tell this change as is warrants a 4.0 release as it is breaking things |
I don't agree @RonnyPfannschmidt... it is a small change, we don't need to make a 4.0 release just because of it. If somebody is relying on this (which I doubt) it is just a matter of adding a try/except over their |
|
This is a matter oft principle, any breaking change we known of gets a major release or we make it non breaking |
|
I don't really mind myself in which version it is released (I doubt many people are depending on this behavior I understand why you wouldn't want to break compatibility), I just think that current behavior is surprising in a harmful way. In my case I only noticed it when I tried to learn which argument had crashed in a tests log, only to discover that ids wasn't really working, |
51912f9 to
cc38ce0
Compare
Hmm OK. What if we make this an opt-in option then? For example: |
|
i would propose to issue a UserWarning or a pytest warning until pytest 4.0 where it should turn into a real exception at the location where the try/catch diaper was, it is possible to consider the config (if it is not we should have a discussion if this should trigger on |
Oh I like this idea. Simpler and we don't need a configuration variable. We can then just remove the try/except in @fogo what do you think? |
|
I've implemented your suggestions as a fixup commit, to be easier to compare with what existed. See what you think about them and if they are ok I'll just rebase later. |
nicoddemus
left a comment
There was a problem hiding this comment.
Apart from my comment about mentioning that this will turn into an error on pytest 4, LGTM!
| s = idfn(val) | ||
| except Exception: | ||
| import warnings | ||
| warnings.warn("Raised while trying to determine id of parameter %s at position %d" % (argname, idx)) |
There was a problem hiding this comment.
I think this will fit well when we integrate pytest-warnings into 3.1. 😁
Could you please add that this will turn into an error on pytest-4.0, something like:
msg = "Raised while trying to determine id of parameter %s at position %d" % (argname, idx)
msg += '\nNote that this will turn into an error in pytest-4.0.'
warnings.warn(msg)There was a problem hiding this comment.
Don't you guys think it'd be better to create an issue for this? Otherwise it may be forgotten when version 4.0 is finally developed.
b363f51 to
a9193a1
Compare
|
@fogo thanks for the fabulous work and for sticking up with the nitpicking |
|
Thanks to you too, guys. I appreciate very much all the care you all take to keep pytest on track. |
|
This will be nice! |
I had recently an issue with a complex parametrized test with a callable
ids. Theidsfunction was wrong but it took me sometime to notice as pytest was silently swallowing any errors when it was called.I changed the code necessary so this won't happen anymore and modified/created some tests.
One more thing though, a question for you, guys: I tried to do some kind of
raise...fromwith a better exception with fixture name but the meta-function information doesn't propagate up to ids function (unlike theconfigobject, which happens to be available there, though it isn't mandatory). If the meta-function got there it'd probably be possible to be way clearer about error, what do you think about this?