use a constant to sort out repeated use of the EMPTY_PARAMETERSET_OPTION

This commit is contained in:
Ronny Pfannschmidt 2018-01-26 12:12:26 +01:00
parent a54cd4c2fd
commit 17a1ed5edf
2 changed files with 13 additions and 8 deletions

View File

@ -13,6 +13,8 @@ from _pytest.config import UsageError
from .deprecated import MARK_PARAMETERSET_UNPACKING from .deprecated import MARK_PARAMETERSET_UNPACKING
from .compat import NOTSET, getfslineno from .compat import NOTSET, getfslineno
EMPTY_PARAMETERSET_OPTION = "empty_parameter_set_mark"
def alias(name, warning=None): def alias(name, warning=None):
getter = attrgetter(name) getter = attrgetter(name)
@ -95,7 +97,7 @@ class ParameterSet(namedtuple('ParameterSet', 'values, marks, id')):
def get_empty_parameterset_mark(config, argnames, function): 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'): if requested_mark in ('', None, 'skip'):
mark = MARK_GEN.skip mark = MARK_GEN.skip
elif requested_mark == 'xfail': elif requested_mark == 'xfail':
@ -148,7 +150,7 @@ def pytest_addoption(parser):
parser.addini("markers", "markers for test functions", 'linelist') parser.addini("markers", "markers for test functions", 'linelist')
parser.addini( parser.addini(
"empty_parameter_set_mark", EMPTY_PARAMETERSET_OPTION,
"default marker for empty parametersets") "default marker for empty parametersets")
@ -293,13 +295,12 @@ def pytest_configure(config):
if config.option.strict: if config.option.strict:
MARK_GEN._config = config 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, ''): if empty_parameterset not in ('skip', 'xfail', None, ''):
from pytest import UsageError
raise UsageError( raise UsageError(
"empty_parameterset must be one of skip and xfail," "{!s} must be one of skip and xfail,"
" but it is {!r}".format(empty_parameterset)) " but it is {!r}".format(EMPTY_PARAMETERSET_OPTION, empty_parameterset))
def pytest_unconfigure(config): def pytest_unconfigure(config):

View File

@ -3,7 +3,10 @@ import os
import sys import sys
import pytest 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): class TestMark(object):
@ -896,7 +899,8 @@ class TestMarkDecorator(object):
@pytest.mark.parametrize('mark', [None, '', 'skip', 'xfail']) @pytest.mark.parametrize('mark', [None, '', 'skip', 'xfail'])
def test_parameterset_for_parametrize_marks(testdir, mark): def test_parameterset_for_parametrize_marks(testdir, mark):
if mark is not None: 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() config = testdir.parseconfig()
from _pytest.mark import pytest_configure, get_empty_parameterset_mark from _pytest.mark import pytest_configure, get_empty_parameterset_mark