From b59376bea4040ccabdf421181f59eaa40c59aa12 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 7 Aug 2015 07:51:59 +0200 Subject: [PATCH] Alert user about other parametrize spellings. --- _pytest/python.py | 11 +++++++---- testing/python/metafunc.py | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index fe93c938e..2a47edca6 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -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: diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 7a6d1eebf..310f7e2f8 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -683,18 +683,20 @@ class TestMetafuncFunctional: 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