Skip to content

AttributeError when typehinting from FixtureRequest.param #11349

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

Closed
4 tasks done
charlesriver456 opened this issue Aug 24, 2023 · 1 comment
Closed
4 tasks done

AttributeError when typehinting from FixtureRequest.param #11349

charlesriver456 opened this issue Aug 24, 2023 · 1 comment

Comments

@charlesriver456
Copy link

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

@The-Compiler
Copy link
Member

The-Compiler commented Aug 24, 2023

I don't quite follow what your goal is with that annotation, but indeed FixtureRequest.param does not exist at runtime and it doesn't make sense to use as a type annotation. Something like Iterator[Tuple[str, str]] would probably be the correct thing to use.

@The-Compiler The-Compiler closed this as not planned Won't fix, can't repro, duplicate, stale Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants