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

combining marks - args and kwargs calculation #2897

Closed
davin-geiger opened this Issue Nov 6, 2017 · 3 comments

Comments

Projects
2 participants
@davin-geiger

davin-geiger commented Nov 6, 2017

If I add the same marker at different code levels (module, class, function) the args of the combined marker will be taken from the "closest" marker and the kwargs from the "farthest" marker.

Example Test

from pytest import mark
pytestmark = mark.test("argument0", Key0="Value0")

@mark.test("argument1", Key0="Value1")
class TestWithClassMarker(object):
    @mark.test("argument2", Key0="Value2")
    def test_marker(self, request):
        test_marker = request.node.get_marker('test')
        test_kwargs = test_marker.kwargs
        test_args = test_marker.args

        assert test_args[0] == "argument2"
        assert test_kwargs['Key0'] == "Value2"

Result

    @mark.test("argument2", Key0="Value2")
    def test_marker(self, request):
        test_marker = request.node.get_marker('test')
        test_kwargs = test_marker.kwargs
        test_args = test_marker.args

        assert test_args[0] == "argument2"
>       assert test_kwargs['Key0'] == "Value2"
E       AssertionError: assert 'Value0' == 'Value2'
E         - Value0
E         ?      ^
E         + Value2
E         ?      ^
@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Nov 6, 2017

thats "expected" behaviour due to mark combination - it can be worked around by iterating the markinfo object to get indivudial marker instances that are noncombined

this is part of the ongoing mark issues
there is a plan to provide a api thats not as broken but it needs time to implement

@davin-geiger

This comment has been minimized.

davin-geiger commented Nov 6, 2017

Thanks for the very quick reply. In that case, I will create my own kwargs by iterating through the markinfos of the marker, as you suggested.

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Apr 10, 2018

fixed in #3317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment