Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,13 @@ def pytest_cmdline_main(config):


def pytest_generate_tests(metafunc):
# this misspelling is common - raise a specific error to alert the user
if hasattr(metafunc.function, 'parameterize'):
msg = "{0} has 'parameterize', spelling should be 'parametrize'"
raise MarkerError(msg.format(metafunc.function.__name__))
# those alternative spellings are common - raise a specific error to alert
# the user
alt_spellings = ['parameterize', 'parametrise', 'parameterise']
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:
markers = metafunc.function.parametrize
except AttributeError:
Expand Down
10 changes: 6 additions & 4 deletions testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,18 +683,20 @@ def test_foo(x):
reprec.assert_outcomes(passed=4)

@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("""
import pytest

@pytest.mark.parameterize("x", range(2))
@pytest.mark.{0}("x", range(2))
def test_foo(x):
pass
""")
""".format(attr))
reprec = testdir.inline_run('--collectonly')
failures = reprec.getfailures()
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


Expand Down