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

Bug: concatenation of marks when creating cases #191

Closed
shaunc opened this issue Mar 4, 2021 · 3 comments
Closed

Bug: concatenation of marks when creating cases #191

shaunc opened this issue Mar 4, 2021 · 3 comments

Comments

@shaunc
Copy link

shaunc commented Mar 4, 2021

I have a class case:

    @case(tags=["med", "categorical"], marks=pytest.mark.slow)
    def case_med(self, feature_case_med):
        return feature_case_med

Using parametrize_with_cases like:

@parametrize_with_cases(
    "case", cases=CasesFeature, has_tag="categorical"
)

I get the following error while decorating the test:

tests/feature/test_feature.py:91: in <module>
    def test_features_to_ranked(snapshot, case):
../../../../../.cache/pypoetry/virtualenvs/emm-5s1w60K6-py3.8/lib/python3.8/site-packages/pytest_cases/common_pytest.py:840: in apply
    return apply_decorator(test_or_fixture_func, container)
../../../../../.cache/pypoetry/virtualenvs/emm-5s1w60K6-py3.8/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:141: in _apply_parametrization
    argvalues = get_parametrize_args(host_class_or_module, cases_funs, prefix=prefix, debug=debug, scope=scope)
../../../../../.cache/pypoetry/virtualenvs/emm-5s1w60K6-py3.8/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:307: in get_parametrize_args
    return [c for _f in cases_funs for c in case_to_argvalues(host_class_or_module, _f, prefix, scope, debug)]
../../../../../.cache/pypoetry/virtualenvs/emm-5s1w60K6-py3.8/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:307: in <listcomp>
    return [c for _f in cases_funs for c in case_to_argvalues(host_class_or_module, _f, prefix, scope, debug)]
../../../../../.cache/pypoetry/virtualenvs/emm-5s1w60K6-py3.8/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:370: in case_to_argvalues
    fix_name, remaining_marks = get_or_create_case_fixture(case_id, case_fun, host_class_or_module,
../../../../../.cache/pypoetry/virtualenvs/emm-5s1w60K6-py3.8/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:477: in get_or_create_case_fixture
    case_marks = get_case_marks(case_fun, concatenate_with_fun_marks=True)
../../../../../.cache/pypoetry/virtualenvs/emm-5s1w60K6-py3.8/lib/python3.8/site-packages/pytest_cases/case_funcs_new.py:187: in get_case_marks
    return (_ci_marks + fun_marks) if _ci_marks else fun_marks
E   TypeError: can only concatenate tuple (not "list") to tuple

The problem is here:

return (_ci_marks + fun_marks) if _ci_marks else fun_marks

where:

(Pdb) _ci_marks
(Mark(name='slow', args=(), kwargs={}),)
(Pdb) fun_marks
[]

simply wrapping fun_marks in tuple() would suffice, but I leave to you to decide if get_pytest_marks_on_function shouldn't better return a tuple in the first place.

@smarie
Copy link
Owner

smarie commented Mar 4, 2021

Nice one ! Thanks @shaunc it seems that you are on "bug killing spree" mode :) I'll fix this and add test

@smarie smarie closed this as completed in bf2c0db Mar 23, 2021
@shaunc
Copy link
Author

shaunc commented Mar 23, 2021

Nice -- I see you fixed the right way. :)

@smarie
Copy link
Owner

smarie commented Mar 24, 2021

Yes apparently tuples are more efficient than lists in general, so I tried to have most functions manipulating marks return tuples. However since get_pytest_marks_on_function was used in many places I was a bit lazy here and left it as it was (returning a list). Thanks again!

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