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

empty parameterset - enable opt to xfail #3044

Merged

Conversation

RonnyPfannschmidt
Copy link
Member

closes #2527

_pytest/mark.py Outdated
from pytest import UsageError
raise UsageError(
"empty_parameterset must be one of skip and xfail,"
" insteat it is {!r}".format(empty_parameterset))
Copy link
Member

Choose a reason for hiding this comment

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

insteat -> instead (but "but" would be a better match probably)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.0004%) to 92.595% when pulling 2b62717 on RonnyPfannschmidt:parameterset-empty-enable-xfail into d872791 on pytest-dev:features.

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.

Looks like a great start, thanks!

Besides the few comments I made, I think we still need to add the documentation for this feature in customize.rst.

fs, lineno = getfslineno(function)
reason = "got empty parameter set %r, function %s at %s:%d" % (
argnames, function.__name__, fs, lineno)
return mark(reason=reason)
Copy link
Member

Choose a reason for hiding this comment

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

For requested_mark == 'xfail' this will be equivalent to MARK_GEN.xfail(run=False)(reason=reason)... is this right?

Copy link
Member Author

Choose a reason for hiding this comment

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

correct

Copy link
Member

Choose a reason for hiding this comment

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

Weird, so pytest.mark.xfail(run=False)(reason=reason) produces the correct result?

Copy link
Member Author

Choose a reason for hiding this comment

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

@nicoddemus pytest marks support compounding addition of args/kwargs

mark.foo(1)(2)(2)(b=2) == mark.foo(1,2,3,b=3)

if mark is None:
# normalize to the requested name
mark = 'skip'
assert result_mark.name == mark
Copy link
Member

Choose a reason for hiding this comment

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

Please also check the reason attribute

@coveralls
Copy link

coveralls commented Dec 26, 2017

Coverage Status

Coverage increased (+0.04%) to 92.669% when pulling 169635e on RonnyPfannschmidt:parameterset-empty-enable-xfail into b8be339 on pytest-dev:features.

@RonnyPfannschmidt
Copy link
Member Author

@nicoddemus changes are implemented, will create a followup issue wrt the deprecation/option change timeline

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.

Thanks @RonnyPfannschmidt it will be great to get this into 3.4. Please take a look at my comments.

_pytest/mark.py Outdated
@@ -97,6 +94,20 @@ def _for_parameterize(cls, argnames, argvalues, function):
return argnames, parameters


def get_empty_parameterset_mark(config, argnames, function):
requested_mark = config.getini('empty_parameterset')
Copy link
Member

Choose a reason for hiding this comment

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

Now that I take a look another look at it, I think this option should be named empty_parameter_set_mark instead, what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

yup, a moment please for the fix

@@ -0,0 +1 @@
introduce a pytest ini option to pick the mark for empty parametersets and allow to use xfail(run=False)
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be improved to be more user-oriented:

Introduce ``empty_parameter_set_mark`` ini option to select which mark to apply when ``@pytest.mark.parametrize`` is given an empty set of parameters. Valid options are ``skip`` (default) and ``xfail``. Note that it is planned to change the default to ``xfail`` in future releases as this is considered less error prone.


.. versionadded:: 3.4

allows to pick the action for empty parametersets in parameterization
Copy link
Member

Choose a reason for hiding this comment

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

This should start with upper case: Allows ...

* ``skip`` skips tests with a empty parameterset
* ``xfail`` marks tests with a empty parameterset as xfail(run=False)

The default is ``skip``, it will be shifted to xfail in future.
Copy link
Member

Choose a reason for hiding this comment

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

I think mentioning that skip is default in its own description is slightly better:

* ``skip`` skips tests with a empty parameter set (default)

And use this paragraph to mention that we plan to change the default in a future release with a link to #3155

@@ -891,3 +891,26 @@ class TestMarkDecorator(object):
])
def test__eq__(self, lhs, rhs, expected):
assert (lhs == rhs) == expected


@pytest.mark.parametrize('mark', [None, 'skip', 'xfail'])
Copy link
Member

Choose a reason for hiding this comment

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

You check for the empty string in the code, should you add an empty string here too I suppose?

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.

Thanks, LGTM!

@RonnyPfannschmidt
Copy link
Member Author

now it should actially pass, there was a small oversight on my part, i think i'd like to create a constant

@nicoddemus
Copy link
Member

@RonnyPfannschmidt took the liberty of making a slight tweak to the docs in 169635e, hope you don't mind. As soon as CI passes we should merge this. 👍

@nicoddemus nicoddemus merged commit b3247c1 into pytest-dev:features Jan 27, 2018
@RonnyPfannschmidt RonnyPfannschmidt deleted the parameterset-empty-enable-xfail branch February 21, 2018 14:25
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.

4 participants