Closed
Description
Parameterized id's used to be able to be integers. Now that crashes verbosely.
- [ x ] Include a detailed description of the bug
Used to be able to have numerical ids in paramterizations.
3.0.0 crashes verbosely if you do that.
- [ x ]
pip list
of the virtual environment you are using
(venv) $ pip list
numpy (1.11.1)
pip (8.1.2)
py (1.4.31)
pymongo (3.3.0)
pytest (3.0.0)
setuptools (20.10.1)
unnecessary-math (0.0.1) - [ x ] pytest and operating system versions
pytest 3.0.0 (tested against 2.9.2 and works there)
os: mac something - [ x ] Minimal example if possible
import pytest
testdata = [( 1, 2), ( 2, 4)]
def times_2(x):
return x * 2
@pytest.mark.parametrize("x,expected", testdata, ids=('a','b'))
def test_ids_strings(x,expected):
'''works in both 3.0.0 and 2.9.2'''
assert times_2(x) == expected
@pytest.mark.parametrize("x,expected", testdata, ids=(1,2))
def test_ids_numbers(x,expected):
'''works in 2.9.2, crashes verbosely in 3.0.0'''
assert times_2(x) == expected
2.9.2:
(venv_2.9.2) $ py.test -v test_ids2.py
================================ test session starts =================================
platform darwin -- Python 3.5.2, pytest-2.9.2, py-1.4.31, pluggy-0.3.1 -- /Users/okken/projects/book/bopytest/Book/code/pytest/um_project/tests/venv_2.9.2/bin/python3.5
cachedir: ../.cache
rootdir: /Users/okken/projects/book/bopytest/Book/code/pytest/um_project, inifile:
collected 4 items
test_ids2.py::test_ids_strings[a] PASSED
test_ids2.py::test_ids_strings[b] PASSED
test_ids2.py::test_ids_numbers[1] PASSED
test_ids2.py::test_ids_numbers[2] PASSED
============================== 4 passed in 0.02 seconds ==============================
3.0.0:
(venv) $ pytest -v test_ids2.py
============================= test session starts ==============================
platform darwin -- Python 3.5.2, pytest-3.0.0, py-1.4.31, pluggy-0.3.1 -- /Users/okken/projects/book/bopytest/Book/venv/bin/python3.5
cachedir: ../.cache
rootdir: /Users/okken/projects/book/bopytest/Book/code/pytest/um_project, inifile:
collected 0 items / 1 errors
==================================== ERRORS ====================================
_____________________ ERROR collecting tests/test_ids2.py ______________________
../../../../venv/lib/python3.5/site-packages/_pytest/runner.py:163: in __init__
self.result = func()
../../../../venv/lib/python3.5/site-packages/_pytest/main.py:460: in _memocollect
return self._memoizedcall('_collected', lambda: list(self.collect()))
../../../../venv/lib/python3.5/site-packages/_pytest/main.py:331: in _memoizedcall
res = function()
../../../../venv/lib/python3.5/site-packages/_pytest/main.py:460: in <lambda>
return self._memoizedcall('_collected', lambda: list(self.collect()))
../../../../venv/lib/python3.5/site-packages/_pytest/python.py:404: in collect
return super(Module, self).collect()
../../../../venv/lib/python3.5/site-packages/_pytest/python.py:318: in collect
res = self.makeitem(name, obj)
../../../../venv/lib/python3.5/site-packages/_pytest/python.py:330: in makeitem
collector=self, name=name, obj=obj)
../../../../venv/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py:724: in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
../../../../venv/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py:338: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
../../../../venv/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py:333: in <lambda>
_MultiCall(methods, kwargs, hook.spec_opts).execute()
../../../../venv/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py:595: in execute
return _wrapped_call(hook_impl.function(*args), self.execute)
../../../../venv/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py:249: in _wrapped_call
wrap_controller.send(call_outcome)
../../../../venv/lib/python3.5/site-packages/_pytest/python.py:191: in pytest_pycollect_makeitem
res = list(collector._genfunctions(name, obj))
../../../../venv/lib/python3.5/site-packages/_pytest/python.py:350: in _genfunctions
self.ihook.pytest_generate_tests(metafunc=metafunc)
../../../../venv/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py:724: in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
../../../../venv/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py:338: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
../../../../venv/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py:333: in <lambda>
_MultiCall(methods, kwargs, hook.spec_opts).execute()
../../../../venv/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py:596: in execute
res = hook_impl.function(*args)
../../../../venv/lib/python3.5/site-packages/_pytest/python.py:104: in pytest_generate_tests
metafunc.parametrize(*marker.args, **marker.kwargs)
../../../../venv/lib/python3.5/site-packages/_pytest/python.py:846: in parametrize
ids = idmaker(argnames, argvalues, idfn, ids, self.config)
../../../../venv/lib/python3.5/site-packages/_pytest/python.py:933: in idmaker
for valindex, valset in enumerate(argvalues)]
../../../../venv/lib/python3.5/site-packages/_pytest/python.py:933: in <listcomp>
for valindex, valset in enumerate(argvalues)]
../../../../venv/lib/python3.5/site-packages/_pytest/python.py:929: in _idvalset
return _escape_strings(ids[idx])
../../../../venv/lib/python3.5/site-packages/_pytest/compat.py:144: in _escape_strings
return val.encode('unicode_escape').decode('ascii')
E AttributeError: 'int' object has no attribute 'encode'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.64 seconds ============================