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

Pytest discovery changes test names when using multiple lazy fixtures #59

Open
fraimondo opened this issue Dec 6, 2022 · 0 comments
Open

Comments

@fraimondo
Copy link

I have some test cases in which I need more than one lazy fixture (one for each parameter).

The problem is that the pytest discovery is creating different test names in every run, which creates a problem in the interaction with tools like VScode. I don't know if it's a pytest issue or pytest-lazy-fixtures one.

Here's an example of a test that uses two lazy fixtures:

import pytest
from pytest import fixture
from pytest_lazyfixture import lazy_fixture


@fixture(params=[1, 2, 3])
def all_numbers(request):
    return request.param


@fixture(params=["a", "b", "c"])
def all_letters(request):
    return request.param


@pytest.mark.parametrize(
    "number,letter",
    [lazy_fixture(["all_numbers", "all_letters"])]
)
def test_multiple_lazy(number, letter):
    print(number, letter)

This is one pytest collect run:

 pytest --collect-only
=================================================================== test session starts ====================================================================
platform darwin -- Python 3.11.0, pytest-7.2.0, pluggy-0.13.1
rootdir: /Users/fraimondo/dev/scratch/pytest_order
plugins: typeguard-2.13.3, lazy-fixture-0.6.3
collected 9 items                                                                                                                                          

<Module test_multiple_lazy.py>
  <Function test_multiple_lazy[all_numbers-all_letters-a-1]>
  <Function test_multiple_lazy[all_numbers-all_letters-a-2]>
  <Function test_multiple_lazy[all_numbers-all_letters-a-3]>
  <Function test_multiple_lazy[all_numbers-all_letters-b-1]>
  <Function test_multiple_lazy[all_numbers-all_letters-b-2]>
  <Function test_multiple_lazy[all_numbers-all_letters-b-3]>
  <Function test_multiple_lazy[all_numbers-all_letters-c-1]>
  <Function test_multiple_lazy[all_numbers-all_letters-c-2]>
  <Function test_multiple_lazy[all_numbers-all_letters-c-3]>

This is another one:

pytest --collect-only
=================================================================== test session starts ====================================================================
platform darwin -- Python 3.11.0, pytest-7.2.0, pluggy-0.13.1
rootdir: /Users/fraimondo/dev/scratch/pytest_order
plugins: typeguard-2.13.3, lazy-fixture-0.6.3
collected 9 items                                                                                                                                          

<Module test_multiple_lazy.py>
  <Function test_multiple_lazy[all_numbers-all_letters-1-a]>
  <Function test_multiple_lazy[all_numbers-all_letters-1-b]>
  <Function test_multiple_lazy[all_numbers-all_letters-1-c]>
  <Function test_multiple_lazy[all_numbers-all_letters-2-a]>
  <Function test_multiple_lazy[all_numbers-all_letters-2-b]>
  <Function test_multiple_lazy[all_numbers-all_letters-2-c]>
  <Function test_multiple_lazy[all_numbers-all_letters-3-a]>
  <Function test_multiple_lazy[all_numbers-all_letters-3-b]>
  <Function test_multiple_lazy[all_numbers-all_letters-3-c]>
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

1 participant