From 91dec8e2bf5e4e9c43b040a8b2f286c8275f8141 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 18 Nov 2019 16:35:34 +0100 Subject: [PATCH] Factor out _validate_parametrize_spelling This makes it easier to read `pytest_generate_tests`. --- src/_pytest/python.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 30853de94..f7436f23b 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -119,14 +119,17 @@ def pytest_cmdline_main(config): return 0 -def pytest_generate_tests(metafunc): - # those alternative spellings are common - raise a specific error to alert - # the user - alt_spellings = ["parameterize", "parametrise", "parameterise"] - for mark_name in alt_spellings: +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): + _validate_parametrize_spelling(metafunc) + for marker in metafunc.definition.iter_markers(name="parametrize"): metafunc.parametrize(*marker.args, **marker.kwargs)