Alert user about other parametrize spellings.
This commit is contained in:
parent
4f83586f55
commit
b59376bea4
|
@ -160,10 +160,13 @@ def pytest_cmdline_main(config):
|
||||||
|
|
||||||
|
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
# this misspelling is common - raise a specific error to alert the user
|
# those alternative spellings are common - raise a specific error to alert
|
||||||
if hasattr(metafunc.function, 'parameterize'):
|
# the user
|
||||||
msg = "{0} has 'parameterize', spelling should be 'parametrize'"
|
alt_spellings = ['parameterize', 'parametrise', 'parameterise']
|
||||||
raise MarkerError(msg.format(metafunc.function.__name__))
|
for attr in alt_spellings:
|
||||||
|
if hasattr(metafunc.function, attr):
|
||||||
|
msg = "{0} has '{1}', spelling should be 'parametrize'"
|
||||||
|
raise MarkerError(msg.format(metafunc.function.__name__, attr))
|
||||||
try:
|
try:
|
||||||
markers = metafunc.function.parametrize
|
markers = metafunc.function.parametrize
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
|
@ -683,18 +683,20 @@ class TestMetafuncFunctional:
|
||||||
reprec.assert_outcomes(passed=4)
|
reprec.assert_outcomes(passed=4)
|
||||||
|
|
||||||
@pytest.mark.issue463
|
@pytest.mark.issue463
|
||||||
def test_parameterize_misspelling(self, testdir):
|
@pytest.mark.parametrize('attr', ['parametrise', 'parameterize',
|
||||||
|
'parameterise'])
|
||||||
|
def test_parametrize_misspelling(self, testdir, attr):
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@pytest.mark.parameterize("x", range(2))
|
@pytest.mark.{0}("x", range(2))
|
||||||
def test_foo(x):
|
def test_foo(x):
|
||||||
pass
|
pass
|
||||||
""")
|
""".format(attr))
|
||||||
reprec = testdir.inline_run('--collectonly')
|
reprec = testdir.inline_run('--collectonly')
|
||||||
failures = reprec.getfailures()
|
failures = reprec.getfailures()
|
||||||
assert len(failures) == 1
|
assert len(failures) == 1
|
||||||
expectederror = "MarkerError: test_foo has 'parameterize', spelling should be 'parametrize'"
|
expectederror = "MarkerError: test_foo has '{0}', spelling should be 'parametrize'".format(attr)
|
||||||
assert expectederror in failures[0].longrepr.reprcrash.message
|
assert expectederror in failures[0].longrepr.reprcrash.message
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue