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

Applying markers directly in parametrize is no longer available in 4.0 #28

Closed
deepbrook opened this issue Nov 16, 2018 · 4 comments
Closed
Labels
compatibility Issues about compatibility with libraries or other packages
Milestone

Comments

@deepbrook
Copy link

import pytest

@pytest.mark.parametrize("x,y", [
    pytest.mark.dependency(name="a1")((0,0)),
    pytest.mark.dependency(name="a2")(pytest.mark.xfail((0,1))),
    pytest.mark.dependency(name="a3")((1,0)),
    pytest.mark.dependency(name="a4")((1,1))
])
def test_a(x,y):
    assert y <= x

@pytest.mark.parametrize("u,v", [
    pytest.mark.dependency(name="b1", depends=["a1", "a2"])((1,2)),
    pytest.mark.dependency(name="b2", depends=["a1", "a3"])((1,3)),
    pytest.mark.dependency(name="b3", depends=["a1", "a4"])((1,4)),
    pytest.mark.dependency(name="b4", depends=["a2", "a3"])((2,3)),
    pytest.mark.dependency(name="b5", depends=["a2", "a4"])((2,4)),
    pytest.mark.dependency(name="b6", depends=["a3", "a4"])((3,4))
])
def test_b(u,v):
    pass

@pytest.mark.parametrize("w", [
    pytest.mark.dependency(name="c1", depends=["b1", "b2", "b6"])(1),
    pytest.mark.dependency(name="c2", depends=["b2", "b3", "b6"])(2),
    pytest.mark.dependency(name="c3", depends=["b2", "b4", "b6"])(3)
])
def test_c(w):
    pass

The above code will fail with the following error in pytest 4.0.0:

custom-eggs/pluggy-0.8.0-py2.7.egg/pluggy/hooks.py:284: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
custom-eggs/pluggy-0.8.0-py2.7.egg/pluggy/manager.py:67: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
custom-eggs/pluggy-0.8.0-py2.7.egg/pluggy/manager.py:61: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
custom-eggs/pytest-4.0.0-py2.7.egg/_pytest/python.py:224: in pytest_pycollect_makeitem
    res = list(collector._genfunctions(name, obj))
custom-eggs/pytest-4.0.0-py2.7.egg/_pytest/python.py:409: in _genfunctions
    self.ihook.pytest_generate_tests(metafunc=metafunc)
custom-eggs/pluggy-0.8.0-py2.7.egg/pluggy/hooks.py:284: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
custom-eggs/pluggy-0.8.0-py2.7.egg/pluggy/manager.py:67: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
custom-eggs/pluggy-0.8.0-py2.7.egg/pluggy/manager.py:61: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
custom-eggs/pytest-4.0.0-py2.7.egg/_pytest/python.py:133: in pytest_generate_tests
    metafunc.parametrize(*marker.args, **marker.kwargs)
custom-eggs/pytest-4.0.0-py2.7.egg/_pytest/python.py:942: in parametrize
    function_definition=self.definition,
custom-eggs/pytest-4.0.0-py2.7.egg/_pytest/mark/structures.py:127: in _for_parametrize
    for x in argvalues
custom-eggs/pytest-4.0.0-py2.7.egg/_pytest/mark/structures.py:110: in extract_from
    belonging_definition.warn(MARK_PARAMETERSET_UNPACKING)
custom-eggs/pytest-4.0.0-py2.7.egg/_pytest/nodes.py:181: in warn
    self._std_warn(_code_or_warning)
custom-eggs/pytest-4.0.0-py2.7.egg/_pytest/nodes.py:232: in _std_warn
    lineno=lineno + 1 if lineno is not None else None,
E   RemovedInPytest4Warning: Applying marks directly to parameters is deprecated, please use pytest.param(..., marks=...) instead.
E   For more details, see: https://docs.pytest.org/en/latest/parametrize.html
@deepbrook
Copy link
Author

deepbrook commented Nov 16, 2018

It's still possible to register a parametrized function with pytest-dependency in order to refer to it in depends of other tests.

However, we can no longer use the name parameter to give it a custom name, nor can we specifiy tests this test case is dependent on using the depends parameter.

The next best thing to the name parameter is using id of pytest.param instead. However, note this will still prepend class names if the test is a class method.

@deepbrook deepbrook changed the title Applying markes directly in parametrize is no longer available in 4.0 Applying markers directly in parametrize is no longer available in 4.0 Nov 18, 2018
@RKrahl RKrahl added this to the 0.3.3 milestone Nov 18, 2018
@RKrahl RKrahl modified the milestones: 0.3.3, 0.4 Dec 2, 2018
@RKrahl RKrahl added the compatibility Issues about compatibility with libraries or other packages label Dec 2, 2018
@RKrahl
Copy link
Owner

RKrahl commented Dec 2, 2018

Thanks for raising this issue. Actually, it is still possible to mark individual test instances and also to use name and depends. But we need to use pytest.param now, see the documentation on parametrizing fixtures and test functions.

@RKrahl RKrahl closed this as completed in ce2861b Dec 2, 2018
@deepbrook
Copy link
Author

So pytest.param passes kwargs it receives but doesn't handle on to the marks that are defined in its call?

@RKrahl
Copy link
Owner

RKrahl commented Dec 2, 2018

pytest.param accepts a marks keyword agrument, see the updated documentation on parametrized tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Issues about compatibility with libraries or other packages
Projects
None yet
Development

No branches or pull requests

2 participants