GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `parametrize` decorator does not work when placed above `staticmethod` · Issue #12863 · pytest-dev/pytest

parametrize decorator does not work when placed above staticmethod #12863

New issue
Copy link
New issue
Copy link
Closed
#13022
Closed
parametrize decorator does not work when placed above staticmethod#12863
#13022
Copy link
Assignees
mikeleppane
Labels
topic: collectionrelated to the collection phasetopic: marksrelated to marks, either the general marks or builtintopic: parametrizerelated to @pytest.mark.parametrizetopic: selectionrelated to test selection from the command linetype: bugproblem that needs to be addressed

Description

@DetachHead
DetachHead
opened on Oct 8, 2024
Issue body actions
  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using (not using pip)
  • pytest and operating system versions
  • minimal example if possible
from pytest import mark

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

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

output of pytest --collect-only:

      <Module test_foo.py>
        <Class TestA>
          <Function test_foo>
          <Function test_bar[1]>
          <Function test_bar[2]>

pytest 8.3.3

it should ideally work for both, but if that's not feasible it should at least raise an exception saying that the decorators are in the wrong order

Reacted by KotlinIsland

Activity

  1. RonnyPfannschmidt
    added
    type: bugproblem that needs to be addressed
    topic: parametrizerelated to @pytest.mark.parametrize
    topic: collectionrelated to the collection phase
    topic: selectionrelated to test selection from the command line
    topic: marksrelated to marks, either the general marks or builtin
    on Oct 8, 2024
  2. mikeleppane commented on Oct 11, 2024

    @mikeleppane
    mikeleppane
    on Oct 11, 2024
    More actions

    Hey! I would be interested in taking a look at this.

    Reacted by Pierre Sassoulas
  3. Pierre-Sassoulas
    assigned
    mikeleppane
    on Oct 11, 2024
  4. eitanwass commented on Dec 2, 2024

    @eitanwass
    eitanwass
    on Dec 2, 2024
    Contributor
    More actions

    Made an attempt at fixing this issue in PR #13022 .

  5. DetachHead commented on Dec 3, 2024

    @DetachHead
    DetachHead
    on Dec 3, 2024
    ContributorAuthor
    More actions

    @eitanwass looks like it's also broken with @classmethod, though at least in this case it prints a warning:

    from pytest import mark
    
    
    class TestA:
        @mark.parametrize("value", [1, 2])
        @classmethod
        def test_foo(cls, value: int):
            """doesn't work"""
    
        @classmethod
        @mark.parametrize("value", [1, 2])
        def test_bar(cls, value: int):
            """works"""
    > pytest --collect-only tests\test_foo.py
    ============================================================================== test session starts ===============================================================================
    platform win32 -- Python 3.13.0, pytest-8.3.3, pluggy-1.5.0
    rootdir: C:\Users\user\project
    configfile: pyproject.toml
    plugins: github-actions-annotate-failures-0.2.0
    collected 2 items
    
    <Dir project>
      <Package tests>
        <Module test_foo.py>
          <Class TestA>
            <Function test_bar[1]>
            <Function test_bar[2]>
    
    ================================================================================ warnings summary ================================================================================
    .venv\Lib\site-packages\_pytest\mark\structures.py:350
      C:\Users\user\project\.venv\Lib\site-packages\_pytest\mark\structures.py:350: PytestCollectionWarning: cannot collect 'test_foo' because it is not a function.
        def __call__(self, *args: object, **kwargs: object):
    
    -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
    =========================================================================== 2 tests collected in 2.09s ===========================================================================
    
  6. eitanwass commented on Dec 3, 2024

    @eitanwass
    eitanwass
    on Dec 3, 2024
    Contributor
    More actions

    Cool. Will check it out tomorrow

    Reacted by DetachHead
  7. eitanwass commented on Dec 4, 2024

    @eitanwass
    eitanwass
    on Dec 4, 2024
    Contributor
    More actions

    @DetachHead updated the PR to fix that problem as well

    Reacted by DetachHead
  8. bluetech
    closed this as completedin #13022on Dec 14, 2024
  9. luketainton
    added a commit that references this issue on Jan 5, 2026

    chore(deps): update dependency pytest to v9 (#305)

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

Metadata

Metadata

Assignees

  • @mikeleppane
    mikeleppane

Labels

topic: collectionrelated to the collection phasetopic: marksrelated to marks, either the general marks or builtintopic: parametrizerelated to @pytest.mark.parametrizetopic: selectionrelated to test selection from the command linetype: bugproblem that needs to be addressed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.