smarie / python-pytest-harvest

Store data created during your `pytest` tests execution, and retrieve it at the end of the session, e.g. for applicative benchmarking purposes.
https://smarie.github.io/python-pytest-harvest/
BSD 3-Clause "New" or "Revised" License
62 stars 9 forks source link

`get_all_pytest_fixture_names` does not return fixtures that are indirectly parametrized or not parametrized. #19

Closed smarie closed 5 years ago

smarie commented 5 years ago
import pytest
from pytest_harvest import get_all_pytest_fixture_names

fixture_params = [1, 2]

@pytest.fixture(params=fixture_params)
def a_number_str_p(request):
    return request.param

@pytest.fixture
def a_number_str(a_number_str_p):
    """ This fixture is indirectly parametrized  by its dependency """
    return "my_fix #%s" % a_number_str_p

def test_foo(a_number_str):
    pass

# --------------

def test_get_all_pytest_fixture_names(request):
    """Tests that get_all_pytest_fixture_names works"""
    fixture_names = get_all_pytest_fixture_names(request.session, filter=test_get_all_pytest_fixture_names.__module__)
    assert fixture_names == ['a_number_str', 'a_number_str_p']  # fails
smarie commented 5 years ago

Note that this is also the case for fixtures that are not parametrized:

@pytest.fixture
def dummy():
    """ This fixture has no parameter """
    return "hello!"

def test_foo2(dummy):
    pass

def test_get_all_pytest_fixture_names_no_param(request):
    """Tests that get_all_pytest_fixture_names works"""
    fixture_names = get_all_pytest_fixture_names(request.session, filter=test_foo2)
    assert fixture_names == ['dummy']  # fails