Skip to content

AUTO cases in conftest: AssertionError #309

Description

@michele-riva

Thanks for the great work! I just stumbled across a corner case.

Example to reproduce:

conftest.py

from pytest_cases import fixture, parametrize_with_cases

@fixture
@parametrize_with_cases('arg')
def auto_cases(arg):
    return arg

test_cases.py

def case():
    return 1

test.py

def test(auto_cases):
    assert auto_cases == 1

Gives

ImportError while loading conftest
pytest_cases/common_pytest.py:925: in apply
    return apply_decorator(test_or_fixture_func, container)
pytest_cases/case_parametrizer_new.py:143: in _apply_parametrization
    cases_funs = get_all_cases(f, cases=cases, prefix=prefix, glob=glob, has_tag=has_tag, filter=filter)
pytest_cases/case_parametrizer_new.py:303: in get_all_cases
    c = import_default_cases_module(caller_module_name)
pytest_cases/case_parametrizer_new.py:670: in import_default_cases_module
    assert parts[-1][0:5] == 'test_'
E   AssertionError: assert 'conft' == 'test_'

Seems very reasonable to me to not allow AUTO use in a conftest.py as it can be ambiguous which cases are to be used for parametrization. However, it probably would be nicer to explicitly check for this and raise a clearer exception? E.g., at the beginning of

def import_default_cases_module(test_module_name):

As a side note, I realized a possible inconsistency in the doc of the @parametrize_with_cases API: it looks like the "second alternative" for looking up cases in AUTO mode is cases_<name>.py (plural), and not case_<name>.py. See

cases_module_name2 = "%s.cases_%s" % ('.'.join(parts[:-1]), parts[-1][5:])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions