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

combining marks - args and kwargs calculation #2897

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

combining marks - args and kwargs calculation #2897

davin-geiger opened this issue Nov 6, 2017 · 3 comments
Labels
topic: marks related to marks, either the general marks or builtin

Comments

@davin-geiger
Copy link

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
Copy link
Member

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

@RonnyPfannschmidt RonnyPfannschmidt added the topic: marks related to marks, either the general marks or builtin label Nov 6, 2017
@davin-geiger
Copy link
Author

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
Copy link
Member

fixed in #3317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: marks related to marks, either the general marks or builtin
Projects
None yet
Development

No branches or pull requests

2 participants