Fail at parametrize option for empty parameter set

Optionally raise an exception when parametrize collects no arguments.
Provide the name of the test causing the failure in the exception
message.

See: #3849
This commit is contained in:
Andrea Cimatoribus
2018-09-12 12:04:45 +02:00
committed by Cima
parent d12f46caef
commit 05155e4db0
3 changed files with 47 additions and 4 deletions

View File

@@ -13,7 +13,7 @@ from _pytest.mark import (
transfer_markers,
EMPTY_PARAMETERSET_OPTION,
)
from _pytest.nodes import Node
from _pytest.nodes import Node, Collector
ignore_markinfo = pytest.mark.filterwarnings(
"ignore:MarkInfo objects:pytest.RemovedInPytest4Warning"
@@ -1091,7 +1091,14 @@ class TestMarkDecorator(object):
@pytest.mark.parametrize("mark", [None, "", "skip", "xfail"])
def test_parameterset_for_parametrize_marks(testdir, mark):
if mark is not None:
testdir.makeini("[pytest]\n{}={}".format(EMPTY_PARAMETERSET_OPTION, mark))
testdir.makeini(
"""
[pytest]
{}={}
""".format(
EMPTY_PARAMETERSET_OPTION, mark
)
)
config = testdir.parseconfig()
from _pytest.mark import pytest_configure, get_empty_parameterset_mark
@@ -1107,6 +1114,34 @@ def test_parameterset_for_parametrize_marks(testdir, mark):
assert result_mark.kwargs.get("run") is False
def test_parameterset_for_fail_at_collect(testdir):
testdir.makeini(
"""
[pytest]
{}=fail_at_collect
""".format(
EMPTY_PARAMETERSET_OPTION
)
)
config = testdir.parseconfig()
from _pytest.mark import pytest_configure, get_empty_parameterset_mark
from _pytest.compat import getfslineno
pytest_configure(config)
test_func = all
func_name = test_func.__name__
_, func_lineno = getfslineno(test_func)
expected_errmsg = r"Empty parameter set in '%s' at line %d" % (
func_name,
func_lineno,
)
with pytest.raises(Collector.CollectError, match=expected_errmsg):
get_empty_parameterset_mark(config, ["a"], test_func)
def test_parameterset_for_parametrize_bad_markname(testdir):
with pytest.raises(pytest.UsageError):
test_parameterset_for_parametrize_marks(testdir, "bad")