From 43e4fcf6dddc6130ff31668b3101dc53de46c9f1 Mon Sep 17 00:00:00 2001 From: Brianna Laugher Date: Mon, 23 Mar 2015 20:01:58 +0100 Subject: [PATCH] Raise specific MarkerError rather than generic ValueError --HG-- branch : issue463 --- _pytest/mark.py | 3 +++ _pytest/python.py | 6 +++--- testing/python/metafunc.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/_pytest/mark.py b/_pytest/mark.py index b9dbe6a7c..06f961496 100644 --- a/_pytest/mark.py +++ b/_pytest/mark.py @@ -1,6 +1,9 @@ """ generic mechanism for marking and selecting python functions. """ import py +class MarkerError(Exception): + """Error in use of a pytest marker/attribute""" + def pytest_namespace(): return {'mark': MarkGenerator()} diff --git a/_pytest/python.py b/_pytest/python.py index 4d57a3c4b..596395062 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -4,7 +4,7 @@ import py import inspect import sys import pytest -from _pytest.mark import MarkDecorator +from _pytest.mark import MarkDecorator, MarkerError from py._code.code import TerminalRepr import _pytest @@ -144,8 +144,8 @@ 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 mark 'parameterize', spelling should be 'parametrize'" - raise ValueError(msg.format(metafunc.function.__name__)) + msg = "{0} has 'parameterize', spelling should be 'parametrize'" + raise MarkerError(msg.format(metafunc.function.__name__)) try: markers = metafunc.function.parametrize except AttributeError: diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index c1a573a47..cbff9adfe 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -704,7 +704,7 @@ class TestMetafuncFunctional: reprec = testdir.inline_run('--collectonly') failures = reprec.getfailures() assert len(failures) == 1 - expectederror = "ValueError: test_foo has mark 'parameterize', spelling should be 'parametrize'" + expectederror = "MarkerError: test_foo has 'parameterize', spelling should be 'parametrize'" assert expectederror in failures[0].longrepr.reprcrash.message