Skip to content

Conversation

@eitanwass
Copy link
Contributor

@eitanwass eitanwass commented Dec 2, 2024

Fixed parametrized markers over staticmethod and classmethod decorators.
closes #12863

An interesting thing about this solution and python (<3.9 vs 3.10<) compatibility:
In python3.10, they changed @staticmethod and @classmethod decorators to inherit method attributes.
Before that version, functions wrapped with them did not return true for callable() func, so it failed tests for py39 and succeeded for py310.
link to changelog

For example:

from pytest import mark

class TestA:
    @mark.parametrize("value", [1, 2])
    @staticmethod
    def test_foo(value: int):
        """Didn't work. Now fixed :)"""

    @pytest.mark.parametrize("value", [1, 2])
    @classmethod
    def test_bar(cls, value: int):
        """Didn't work. Now fixed :)"""

    @staticmethod
    @mark.parametrize("value", [1, 2])
    def test_baz(value: int):
        """Works"""

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Dec 2, 2024
@eitanwass eitanwass marked this pull request as draft December 2, 2024 21:01
@eitanwass eitanwass marked this pull request as ready for review December 4, 2024 18:16
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this @eitanwass! I left a couple of suggestions/questions.

@eitanwass eitanwass requested a review from bluetech December 5, 2024 17:45
@eitanwass eitanwass requested a review from bluetech December 6, 2024 07:17
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

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

Thanks!

@bluetech bluetech merged commit 6dd3fff into pytest-dev:main Dec 14, 2024
28 checks passed
@bluetech
Copy link
Member

Hmph, should have squashed...

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

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parametrize decorator does not work when placed above staticmethod

2 participants