From 17a1ed5edf73e12d14665a2e6ed2399ae6415579 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 26 Jan 2018 12:12:26 +0100 Subject: [PATCH] use a constant to sort out repeated use of the EMPTY_PARAMETERSET_OPTION --- _pytest/mark.py | 13 +++++++------ testing/test_mark.py | 8 ++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/_pytest/mark.py b/_pytest/mark.py index e5d956252..b49f0fc64 100644 --- a/_pytest/mark.py +++ b/_pytest/mark.py @@ -13,6 +13,8 @@ from _pytest.config import UsageError from .deprecated import MARK_PARAMETERSET_UNPACKING from .compat import NOTSET, getfslineno +EMPTY_PARAMETERSET_OPTION = "empty_parameter_set_mark" + def alias(name, warning=None): getter = attrgetter(name) @@ -95,7 +97,7 @@ class ParameterSet(namedtuple('ParameterSet', 'values, marks, id')): def get_empty_parameterset_mark(config, argnames, function): - requested_mark = config.getini('empty_parameter_set_mark') + requested_mark = config.getini(EMPTY_PARAMETERSET_OPTION) if requested_mark in ('', None, 'skip'): mark = MARK_GEN.skip elif requested_mark == 'xfail': @@ -148,7 +150,7 @@ def pytest_addoption(parser): parser.addini("markers", "markers for test functions", 'linelist') parser.addini( - "empty_parameter_set_mark", + EMPTY_PARAMETERSET_OPTION, "default marker for empty parametersets") @@ -293,13 +295,12 @@ def pytest_configure(config): if config.option.strict: MARK_GEN._config = config - empty_parameterset = config.getini("empty_parameter_set_mark") + empty_parameterset = config.getini(EMPTY_PARAMETERSET_OPTION) if empty_parameterset not in ('skip', 'xfail', None, ''): - from pytest import UsageError raise UsageError( - "empty_parameterset must be one of skip and xfail," - " but it is {!r}".format(empty_parameterset)) + "{!s} must be one of skip and xfail," + " but it is {!r}".format(EMPTY_PARAMETERSET_OPTION, empty_parameterset)) def pytest_unconfigure(config): diff --git a/testing/test_mark.py b/testing/test_mark.py index c3a80083c..b4dd65634 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -3,7 +3,10 @@ import os import sys import pytest -from _pytest.mark import MarkGenerator as Mark, ParameterSet, transfer_markers +from _pytest.mark import ( + MarkGenerator as Mark, ParameterSet, transfer_markers, + EMPTY_PARAMETERSET_OPTION, +) class TestMark(object): @@ -896,7 +899,8 @@ class TestMarkDecorator(object): @pytest.mark.parametrize('mark', [None, '', 'skip', 'xfail']) def test_parameterset_for_parametrize_marks(testdir, mark): if mark is not None: - testdir.makeini("[pytest]\nempty_parameter_set_mark=" + mark) + testdir.makeini( + "[pytest]\n{}={}".format(EMPTY_PARAMETERSET_OPTION, mark)) config = testdir.parseconfig() from _pytest.mark import pytest_configure, get_empty_parameterset_mark