-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Can't mark.xfail a callable test param #552
Comments
Original comment by Tom V (BitBucket: tomviner, GitHub: tomviner): I can see what's causing this now, and I have a work around. MarkDecorator acts differently when passed a "single callable argument". So the solution is to make sure you pass another argument to mark.xfail, and only one is valid: reason. To see what's going on here, these two pytest.mark.parametrize expressions only differ on the reason argument:
So applying this workaround to the original example above now works as expected, although realising this clearly wasn't straightforward:
And this works for all the param types causing unexpected erroring xfails above. Not sure what action this issue requires now? Clearer docs at the minimum, but cleverer code to detect this scenario would be even better. |
Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42): I guess passing in "reason" is the cleanest solution for now. You could probably also do We could maybe generate a warning based on detecting if the function name of a marker first arg does not have a "test" prefix. Or even assume it's meant as an argument rather directly decorating things. |
Original comment by Tom V (BitBucket: tomviner, GitHub: tomviner): Re trying
I tried your suggestion of detecting if the function name of a marker first arg does not have a "test" prefix: Implementation and failing tests, because lots of functions are decorated in the tests without having I would say nope: I've found code in the wild that mark decorates non-tests. But maybe a warning, as you mentioned, would be helpful? There'd need to be no use case for decorating a non-test. But isn't the way pytest collects tests highly configurable, so ultimately there's no way to know if something is a test function/method/class or not? So being conservative, we're back to a documentation note. It's an unfortunate ambiguity caused by Python's decorator flexibility. If you're in agreement Holger, I'll write a docs patch. |
Original comment by Tom V (BitBucket: tomviner, GitHub: tomviner): https://bitbucket.org/hpk42/pytest/pull-request/222/fix-issue552-add-a-note-to-the-docs-about/diff |
Originally reported by: Tom V (BitBucket: tomviner, GitHub: tomviner)
Within a
pytest.mark.parametrize
decorator, marking xfail on a (non-lambda) callable likepytest.mark.xfail(func)
doesn't work.These first 3 examples contain marked xfails for the 2nd param, but still show as failed tests when run:
Output:
And some examples where it behaves as expected, with non-callables (and lambdas):
And the output, which is what I expect regardless of the type of the params:
The text was updated successfully, but these errors were encountered: