Skip to content

Commit fd4d35d

Browse files
committed
Merge pull request #924 from The-Compiler/parametrise
Alert user about other parametrize spellings.
2 parents 4f83586 + b59376b commit fd4d35d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

_pytest/python.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,13 @@ def pytest_cmdline_main(config):
160160

161161

162162
def pytest_generate_tests(metafunc):
163-
# this misspelling is common - raise a specific error to alert the user
164-
if hasattr(metafunc.function, 'parameterize'):
165-
msg = "{0} has 'parameterize', spelling should be 'parametrize'"
166-
raise MarkerError(msg.format(metafunc.function.__name__))
163+
# those alternative spellings are common - raise a specific error to alert
164+
# the user
165+
alt_spellings = ['parameterize', 'parametrise', 'parameterise']
166+
for attr in alt_spellings:
167+
if hasattr(metafunc.function, attr):
168+
msg = "{0} has '{1}', spelling should be 'parametrize'"
169+
raise MarkerError(msg.format(metafunc.function.__name__, attr))
167170
try:
168171
markers = metafunc.function.parametrize
169172
except AttributeError:

testing/python/metafunc.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,18 +683,20 @@ def test_foo(x):
683683
reprec.assert_outcomes(passed=4)
684684

685685
@pytest.mark.issue463
686-
def test_parameterize_misspelling(self, testdir):
686+
@pytest.mark.parametrize('attr', ['parametrise', 'parameterize',
687+
'parameterise'])
688+
def test_parametrize_misspelling(self, testdir, attr):
687689
testdir.makepyfile("""
688690
import pytest
689691
690-
@pytest.mark.parameterize("x", range(2))
692+
@pytest.mark.{0}("x", range(2))
691693
def test_foo(x):
692694
pass
693-
""")
695+
""".format(attr))
694696
reprec = testdir.inline_run('--collectonly')
695697
failures = reprec.getfailures()
696698
assert len(failures) == 1
697-
expectederror = "MarkerError: test_foo has 'parameterize', spelling should be 'parametrize'"
699+
expectederror = "MarkerError: test_foo has '{0}', spelling should be 'parametrize'".format(attr)
698700
assert expectederror in failures[0].longrepr.reprcrash.message
699701

700702

0 commit comments

Comments
 (0)