Skip to content

AttributeError when typehinting from FixtureRequest.param #11349

Description

@charlesriver456

Hello, I'm using FixtureRequest and it's associated param value when writing tests. When I run pytest file_name.py I get the following error message: AttributeError: type object 'FixtureRequest' has no attribute 'param'. I believe this is because I am type-hinting with FixtureRequest.param. I saw the notes from #10133 on using when parameterizing fixtures, which I believe I am doing here (let me know if not!). See the code block below to understand how I am using it and the screenshot for my pytest version/pip list output. Thank you!

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Code block:

import pytest
from pytest import FixtureRequest
from typing import List, Tuple

def _create_list_of_tuples() -> List[Tuple]:
    first_group = ['a', 'b', 'c']
    second_group = ['a', 'b', 'c']
    return list(zip(first_group, second_group))

@pytest.fixture(params=_create_list_of_tuples())
def get_zipped_groups(request: FixtureRequest) -> FixtureRequest.param:
    yield request.param

def test_equality(get_zipped_groups: Tuple[str, str]) -> None:
    first: str = get_zipped_groups[0]
    second: str = get_zipped_groups[1]
    assert first == second

pip list output:

image

My env:
macOS-13.4
Python 3.8.17

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions