Merge pull request #1530 from RonnyPfannschmidt/fix-510

fix #510 by adding a describing skip marker on empty parameterize
This commit is contained in:
Bruno Oliveira 2016-05-30 10:54:33 -03:00
commit 82c74fe7e6
3 changed files with 31 additions and 25 deletions

View File

@ -3,7 +3,8 @@
**Bug Fixes** **Bug Fixes**
* * fix `#510`_: skip tests where one parameterize dimension was empty
thanks Alex Stapleton for the Report and `@RonnyPfannschmidt`_ for the PR
* Fix win32 path issue when puttinging custom config file with absolute path * Fix win32 path issue when puttinging custom config file with absolute path
in ``pytest.main("-c your_absolute_path")``. in ``pytest.main("-c your_absolute_path")``.
@ -19,7 +20,7 @@
* Minor improvements and fixes to the documentation. * Minor improvements and fixes to the documentation.
Thanks `@omarkohl`_ for the PR. Thanks `@omarkohl`_ for the PR.
.. _#510: https://github.com/pytest-dev/pytest/issues/510
.. _#1506: https://github.com/pytest-dev/pytest/pull/1506 .. _#1506: https://github.com/pytest-dev/pytest/pull/1506
.. _@prusse-martin: https://github.com/prusse-martin .. _@prusse-martin: https://github.com/prusse-martin

View File

@ -871,8 +871,6 @@ class CallSpec2(object):
getattr(self, valtype_for_arg)[arg] = val getattr(self, valtype_for_arg)[arg] = val
self.indices[arg] = param_index self.indices[arg] = param_index
self._arg2scopenum[arg] = scopenum self._arg2scopenum[arg] = scopenum
if val is _notexists:
self._emptyparamspecified = True
self._idlist.append(id) self._idlist.append(id)
self.keywords.update(keywords) self.keywords.update(keywords)
@ -990,6 +988,15 @@ class Metafunc(FuncargnamesCompatAttr):
argvalues = [(val,) for val in argvalues] argvalues = [(val,) for val in argvalues]
if not argvalues: if not argvalues:
argvalues = [(_notexists,) * len(argnames)] argvalues = [(_notexists,) * len(argnames)]
# we passed a empty list to parameterize, skip that test
#
fs, lineno = getfslineno(self.function)
newmark = pytest.mark.skip(
reason="got empty parameter set %r, function %s at %s:%d" % (
argnames, self.function.__name__, fs, lineno))
newmarks = newkeywords.setdefault(0, {})
newmarks[newmark.markname] = newmark
if scope is None: if scope is None:
scope = "function" scope = "function"
@ -1408,15 +1415,6 @@ class Function(FunctionMixin, pytest.Item, FuncargnamesCompatAttr):
self.ihook.pytest_pyfunc_call(pyfuncitem=self) self.ihook.pytest_pyfunc_call(pyfuncitem=self)
def setup(self): def setup(self):
# check if parametrization happend with an empty list
try:
self.callspec._emptyparamspecified
except AttributeError:
pass
else:
fs, lineno = self._getfslineno()
pytest.skip("got empty parameter set, function %s at %s:%d" %(
self.function.__name__, fs, lineno))
super(Function, self).setup() super(Function, self).setup()
fillfixtures(self) fillfixtures(self)

View File

@ -109,6 +109,13 @@ class TestMetafunc:
metafunc.parametrize(("x","y"), [("abc", "def"), metafunc.parametrize(("x","y"), [("abc", "def"),
("ghi", "jkl")], ids=["one"])) ("ghi", "jkl")], ids=["one"]))
@pytest.mark.issue510
def test_parametrize_empty_list(self):
def func( y): pass
metafunc = self.Metafunc(func)
metafunc.parametrize("y", [])
assert 'skip' in metafunc._calls[0].keywords
def test_parametrize_with_userobjects(self): def test_parametrize_with_userobjects(self):
def func(x, y): pass def func(x, y): pass
metafunc = self.Metafunc(func) metafunc = self.Metafunc(func)