[pytest-dev] fixture params must be immutable?

holger krekel holger at merlinux.eu
Tue Apr 9 11:50:53 CEST 2013


On Mon, Apr 08, 2013 at 10:57 -0400, Ofer Nave wrote:
> Been using pytest for a few days and enjoying it greatly.  However,
> the last bit of code I wrote just blew up with "INTERNALERROR>
> TypeError: unhashable type: 'dict'".
> 
> It seems that if you parameterize a fixture function, it must be
> with a list of immutable values.  This works:
> 
> @pytest.fixture(params=[1, 2, 3])
> def foo(request):
>     return request.param
> def bar(foo):
>     assert foo
> 
> This doesn't:
> 
> @pytest.fixture(params=[{a:1}, {a:2}, {a:3}])
> def foo(request):
>     return request.param
> def bar(foo):
>     assert foo
> 
> ...because dict is immutable.
> 
> I didn't see this requirement mentioned in the docs, and I don't
> understand why it would be the case.  Looking for enlightenment.

The parametrization implementation needs to be refactored to
avoid this problem.  There is also a related issue here suffering
from a similar shortcoming: https://bitbucket.org/hpk42/pytest/issue/290/

the refactoring needs to avoid doing anything with the values (like
hashing, putting them in a dict etc.) but rather work with indexes
into the param values set.  

Maybe best open an issue, and reference issue290, so we don't
forget it.  Not bound to tackle this myself, however, in the 
next weeks i think.

best,
holger


> -ofer
> _______________________________________________
> Pytest-dev mailing list
> Pytest-dev at python.org
> http://mail.python.org/mailman/listinfo/pytest-dev
> 


More information about the Pytest-dev mailing list