Merge pull request #6231 from blueyed/param-spell
Improve check for misspelling of parametrize
This commit is contained in:
commit
1d368e0ed4
|
@ -0,0 +1 @@
|
||||||
|
Improve check for misspelling of ``pytest.mark.parametrize``.
|
|
@ -314,13 +314,18 @@ class MarkGenerator:
|
||||||
"{!r} not found in `markers` configuration option".format(name),
|
"{!r} not found in `markers` configuration option".format(name),
|
||||||
pytrace=False,
|
pytrace=False,
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
warnings.warn(
|
# Raise a specific error for common misspellings of "parametrize".
|
||||||
"Unknown pytest.mark.%s - is this a typo? You can register "
|
if name in ["parameterize", "parametrise", "parameterise"]:
|
||||||
"custom marks to avoid this warning - for details, see "
|
__tracebackhide__ = True
|
||||||
"https://docs.pytest.org/en/latest/mark.html" % name,
|
fail("Unknown '{}' mark, did you mean 'parametrize'?".format(name))
|
||||||
PytestUnknownMarkWarning,
|
|
||||||
)
|
warnings.warn(
|
||||||
|
"Unknown pytest.mark.%s - is this a typo? You can register "
|
||||||
|
"custom marks to avoid this warning - for details, see "
|
||||||
|
"https://docs.pytest.org/en/latest/mark.html" % name,
|
||||||
|
PytestUnknownMarkWarning,
|
||||||
|
)
|
||||||
|
|
||||||
return MarkDecorator(Mark(name, (), {}))
|
return MarkDecorator(Mark(name, (), {}))
|
||||||
|
|
||||||
|
|
|
@ -120,17 +120,7 @@ def pytest_cmdline_main(config):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def _validate_parametrize_spelling(metafunc):
|
|
||||||
"""Raise a specific error for common misspellings of "parametrize"."""
|
|
||||||
for mark_name in ["parameterize", "parametrise", "parameterise"]:
|
|
||||||
if metafunc.definition.get_closest_marker(mark_name):
|
|
||||||
msg = "{0} has '{1}' mark, spelling should be 'parametrize'"
|
|
||||||
fail(msg.format(metafunc.function.__name__, mark_name), pytrace=False)
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
_validate_parametrize_spelling(metafunc)
|
|
||||||
|
|
||||||
for marker in metafunc.definition.iter_markers(name="parametrize"):
|
for marker in metafunc.definition.iter_markers(name="parametrize"):
|
||||||
metafunc.parametrize(*marker.args, **marker.kwargs)
|
metafunc.parametrize(*marker.args, **marker.kwargs)
|
||||||
|
|
||||||
|
|
|
@ -1323,25 +1323,29 @@ class TestMetafuncFunctional:
|
||||||
reprec = testdir.runpytest()
|
reprec = testdir.runpytest()
|
||||||
reprec.assert_outcomes(passed=4)
|
reprec.assert_outcomes(passed=4)
|
||||||
|
|
||||||
@pytest.mark.parametrize("attr", ["parametrise", "parameterize", "parameterise"])
|
def test_parametrize_misspelling(self, testdir):
|
||||||
def test_parametrize_misspelling(self, testdir, attr):
|
|
||||||
"""#463"""
|
"""#463"""
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@pytest.mark.{}("x", range(2))
|
@pytest.mark.parametrise("x", range(2))
|
||||||
def test_foo(x):
|
def test_foo(x):
|
||||||
pass
|
pass
|
||||||
""".format(
|
"""
|
||||||
attr
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("--collectonly")
|
result = testdir.runpytest("--collectonly")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
[
|
[
|
||||||
"test_foo has '{}' mark, spelling should be 'parametrize'".format(attr),
|
"collected 0 items / 1 error",
|
||||||
"*1 error in*",
|
"",
|
||||||
|
"*= ERRORS =*",
|
||||||
|
"*_ ERROR collecting test_parametrize_misspelling.py _*",
|
||||||
|
"test_parametrize_misspelling.py:3: in <module>",
|
||||||
|
' @pytest.mark.parametrise("x", range(2))',
|
||||||
|
"E Failed: Unknown 'parametrise' mark, did you mean 'parametrize'?",
|
||||||
|
"*! Interrupted: 1 error during collection !*",
|
||||||
|
"*= 1 error in *",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue