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

fixture not found when using parametrized case from case file #128

Closed
last-partizan opened this issue Aug 20, 2020 · 6 comments
Closed

fixture not found when using parametrized case from case file #128

last-partizan opened this issue Aug 20, 2020 · 6 comments

Comments

@last-partizan
Copy link

Hello, i found a strange behaviour when using parametrized cases.

Here is example:

test.py

from pytest_cases import parametrize_with_cases, fixture


@parametrize_with_cases("v")
def test(v):
    assert v == "one_proud_bird"


@fixture
def bird():
    return "one_proud_bird"

test_cases.py

def case_one(bird):
    return bird

This is failing with "Fixture 'one' not found", but only when used parameter for case AND cases in separate file or class. When case with fixture in the same file, it works fine. Here is full test log:

poetry run pytest test.py

============================================== test session starts ==============================================
platform linux -- Python 3.8.5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /home/serg/pyright-test/tests
plugins: cases-2.1.3
collected 1 item                                                                                                

test.py E                                                                                                 [100%]

==================================================== ERRORS =====================================================
_______________________________________ ERROR at setup of test[v_is_one] ________________________________________
file /home/serg/pyright-test/tests/test.py, line 5: source code not available
file <makefun-gen-8>, line 1: source code not available
E       fixture 'one' not found
>       available fixtures: bird, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, test_v, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

<makefun-gen-8>:1
============================================ short test summary info ============================================
ERROR test.py::test[v_is_one]
=============================================== 1 error in 0.02s ================================================
@last-partizan
Copy link
Author

Note: this is not related to @fixture from pytest-cases, it happens with pytest.fixture, and built-in pytest fixtures too. pytest_cases.fixture here is just an example.

@smarie
Copy link
Owner

smarie commented Aug 20, 2020

Thanks @last-partizan ! Can you please try with latest version 2.2.0 released yesterday ? It seems to have fixed the issue.

@last-partizan
Copy link
Author

@smarie yep, this is working now!

But i have another broken exmaple :))

from pytest_cases import parametrize_with_cases, fixture


class Cases:

    def case_one(self, bird):
        return "one"

    def case_two(self):
        return "two"


@parametrize_with_cases("v", cases=Cases)
def test_this_is_failing(v):
    assert v in ["one", "two"]


@fixture
def bird():
    return "one_proud_bird"

produces:

============================================== test session starts ==============================================
platform linux -- Python 3.8.5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /home/serg/pyright-test/tests
plugins: cases-2.2.0
collected 0 items / 1 error                                                                                     

==================================================== ERRORS =====================================================
___________________________________________ ERROR collecting test.py ____________________________________________
test.py:15: in <module>
    def test_this_is_failing(v):
../../.cache/pypoetry/virtualenvs/pyright-test-iQO7wX6m-py3.8/lib/python3.8/site-packages/pytest_cases/common_pytest.py:719: in apply
    return apply_decorator(test_or_fixture_func, container)
../../.cache/pypoetry/virtualenvs/pyright-test-iQO7wX6m-py3.8/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:107: in _apply_parametrization
    argvalues = get_parametrize_args(host_class_or_module, cases_funs, debug=debug)
../../.cache/pypoetry/virtualenvs/pyright-test-iQO7wX6m-py3.8/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:254: in get_parametrize_args
    return [c for _f in cases_funs for c in case_to_argvalues(host_class_or_module, _f, debug)]
../../.cache/pypoetry/virtualenvs/pyright-test-iQO7wX6m-py3.8/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:254: in <listcomp>
    return [c for _f in cases_funs for c in case_to_argvalues(host_class_or_module, _f, debug)]
../../.cache/pypoetry/virtualenvs/pyright-test-iQO7wX6m-py3.8/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:300: in case_to_argvalues
    fix_name = get_or_create_case_fixture(case_id, case_fun, host_class_or_module, debug)
../../.cache/pypoetry/virtualenvs/pyright-test-iQO7wX6m-py3.8/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:388: in get_or_create_case_fixture
    case_fun = funcopy(case_fun)
../../.cache/pypoetry/virtualenvs/pyright-test-iQO7wX6m-py3.8/lib/python3.8/site-packages/pytest_cases/case_parametrizer_new.py:380: in funcopy
    return makefun.partial(f)
../../.cache/pypoetry/virtualenvs/pyright-test-iQO7wX6m-py3.8/lib/python3.8/site-packages/makefun/main.py:928: in partial
    @wraps(f, new_sig=new_sig)
../../.cache/pypoetry/virtualenvs/pyright-test-iQO7wX6m-py3.8/lib/python3.8/site-packages/makefun/main.py:667: in wraps
    func_name, func_sig, doc, qualname, module_name, all_attrs = _get_args_for_wrapping(f, new_sig, func_name, doc,
../../.cache/pypoetry/virtualenvs/pyright-test-iQO7wX6m-py3.8/lib/python3.8/site-packages/makefun/main.py:704: in _get_args_for_wrapping
    module_name = wrapped.__module__
E   AttributeError: 'functools.partial' object has no attribute '__module__'
============================================ short test summary info ============================================
ERROR test.py - AttributeError: 'functools.partial' object has no attribute '__module__'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=============================================== 1 error in 0.09s ================================================

@smarie
Copy link
Owner

smarie commented Aug 20, 2020

Updating makefun to 1.9.3 should fix the problem. I'll update setup.py to enforce this.

smarie pushed a commit that referenced this issue Aug 20, 2020
…buteError: 'functools.partial' object has no attribute '__module__'` mentioned in #128
@last-partizan
Copy link
Author

This is fixed now! Thank you!

======================================= test session starts ========================================
platform linux -- Python 3.8.5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 -- /home/serg/.cache/pypoetry/virtualenvs/pyright-test-iQO7wX6m-py3.8/bin/python
cachedir: .pytest_cache
rootdir: /home/serg/pyright-test/tests
plugins: cases-2.2.1
collected 4 items                                                                                  

test.py::test_this_is_ok[v_is_one] PASSED                                                    [ 25%]
test.py::test_was_failing_with_case_class[v_is_one_] PASSED                                  [ 50%]
test.py::test_was_failing_with_case_class[v_is_two] PASSED                                   [ 75%]
test.py::test_this_was_failing_with_case_file[v_is_one__] PASSED                             [100%]

======================================== 4 passed in 0.02s =========================================

@smarie
Copy link
Owner

smarie commented Aug 21, 2020

Thanks @last-partizan !

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