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 with numpy array as value fails on 0.6.0 #42

Closed
jorisvandenbossche opened this issue Oct 14, 2019 · 3 comments
Closed

Fixture with numpy array as value fails on 0.6.0 #42

jorisvandenbossche opened this issue Oct 14, 2019 · 3 comments

Comments

@jorisvandenbossche
Copy link

jorisvandenbossche commented Oct 14, 2019

This seems related to pytest-dev/pytest#5946 (which is already fixed on pytest master), but it is still failing with the latest lazy-fixtures (pinning to 0.5.2 fixes it).

Test script (variation of the one in pytest-dev/pytest#5946):

import numpy as np
import pytest


@pytest.mark.parametrize(
    'value',
    [
        np.arange(10, dtype=np.int64),
        np.arange(10, dtype=np.int32),
    ]
)
def test_bug(value):
    assert isinstance(value, np.ndarray)

and this fails with:

$ pytest test_pytest_bug.py -v
==================================================================== test session starts =====================================================================
platform linux -- Python 3.7.3, pytest-5.2.2.dev23+ga20880cca, py-1.8.0, pluggy-0.12.0 -- /home/joris/miniconda3/envs/arrow-dev/bin/python
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/joris/scipy/.hypothesis/examples')
rootdir: /home/joris/scipy
plugins: hypothesis-4.24.2, lazy-fixture-0.6.0
collected 2 items                                                                                                                                            

test_pytest_bug.py::test_bug[value0] ERROR                                                                                                             [ 50%]
test_pytest_bug.py::test_bug[value1] ERROR                                                                                                             [100%]

=========================================================================== ERRORS ===========================================================================
_____________________________________________________________ ERROR at setup of test_bug[value0] _____________________________________________________________

request = <FixtureRequest for <Function test_bug[value0]>>

    def fill(request):
        item = request._pyfuncitem
        fixturenames = getattr(item, "fixturenames", None)
        if fixturenames is None:
            fixturenames = request.fixturenames
    
        if hasattr(item, 'callspec'):
>           for param, val in sorted_by_dependency(item.callspec.params, fixturenames):

../miniconda3/envs/arrow-dev/lib/python3.7/site-packages/pytest_lazyfixture.py:33: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

params = {'value': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, fixturenames = ['value']

    def sorted_by_dependency(params, fixturenames):
        free_fm = []
        non_free_fm = defaultdict(list)
    
        for key in _sorted_argnames(params, fixturenames):
            val = params.get(key)
    
>           if not val or not is_lazy_fixture(val) or val.name not in params:
E           ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

../miniconda3/envs/arrow-dev/lib/python3.7/site-packages/pytest_lazyfixture.py:130: ValueError
_____________________________________________________________ ERROR at setup of test_bug[value1] _____________________________________________________________

request = <FixtureRequest for <Function test_bug[value1]>>

    def fill(request):
        item = request._pyfuncitem
        fixturenames = getattr(item, "fixturenames", None)
        if fixturenames is None:
            fixturenames = request.fixturenames
    
        if hasattr(item, 'callspec'):
>           for param, val in sorted_by_dependency(item.callspec.params, fixturenames):

../miniconda3/envs/arrow-dev/lib/python3.7/site-packages/pytest_lazyfixture.py:33: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

params = {'value': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32)}, fixturenames = ['value']

    def sorted_by_dependency(params, fixturenames):
        free_fm = []
        non_free_fm = defaultdict(list)
    
        for key in _sorted_argnames(params, fixturenames):
            val = params.get(key)
    
>           if not val or not is_lazy_fixture(val) or val.name not in params:
E           ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

../miniconda3/envs/arrow-dev/lib/python3.7/site-packages/pytest_lazyfixture.py:130: ValueError
====================================================================== 2 error in 0.09s ======================================================================

@TvoroG
Copy link
Owner

TvoroG commented Oct 14, 2019

Thanks for the issue! Can you test branch https://github.com/TvoroG/pytest-lazy-fixture/tree/issues42 and confirm that it works for you?

@jorisvandenbossche
Copy link
Author

Yes, that seems to work! Thanks for the quick follow-up

@TvoroG
Copy link
Owner

TvoroG commented Oct 14, 2019

Thanks! Released 0.6.1

@TvoroG TvoroG closed this as completed Oct 14, 2019
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