Remove unused markers and enable --strict-markers

This commit is contained in:
Bruno Oliveira 2019-04-27 11:43:36 -03:00
parent f1183c2422
commit 0594dba5ce
6 changed files with 21 additions and 21 deletions

View File

@ -1 +1,5 @@
``--strict`` is now called ``--strict-markers`` as it is more explicit about what it does. The old name still works for backward compatibility. New flag ``--strict-markers`` that triggers an error when unknown markers (e.g. those not registered using the `markers option`_ in the configuration file) are used in the test suite.
The existing ``--strict`` option has the same behavior currently, but can be augmented in the future for additional checks.
.. _`markers option`: https://docs.pytest.org/en/latest/reference.html#confval-markers

View File

@ -1261,8 +1261,8 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: markers .. confval:: markers
When the ``--strict-markers`` command-line argument is used, only known markers - When the ``--strict-markers`` or ``--strict`` command-line arguments are used,
defined in code by core pytest or some plugin - are allowed. only known markers - defined in code by core pytest or some plugin - are allowed.
You can list additional markers in this setting to add them to the whitelist, You can list additional markers in this setting to add them to the whitelist,
in which case you probably want to add ``--strict-markers`` to ``addopts`` in which case you probably want to add ``--strict-markers`` to ``addopts``
@ -1276,9 +1276,6 @@ passed multiple times. The expected format is ``name=value``. For example::
slow slow
serial serial
**Note**: This option was previously called ``--strict``, which is now an
alias preserved for backward compatibility.
.. confval:: minversion .. confval:: minversion
Specifies a minimal pytest version required for running tests. Specifies a minimal pytest version required for running tests.

View File

@ -11,7 +11,6 @@ import textwrap
import py import py
import six import six
from six.moves import queue from six.moves import queue
from test_source import astonly
import _pytest import _pytest
import pytest import pytest
@ -147,7 +146,6 @@ class TestTraceback_f_g_h(object):
assert s.startswith("def f():") assert s.startswith("def f():")
assert s.endswith("raise ValueError") assert s.endswith("raise ValueError")
@astonly
@failsonjython @failsonjython
def test_traceback_entry_getsource_in_construct(self): def test_traceback_entry_getsource_in_construct(self):
source = _pytest._code.Source( source = _pytest._code.Source(

View File

@ -16,7 +16,6 @@ import _pytest._code
import pytest import pytest
from _pytest._code import Source from _pytest._code import Source
astonly = pytest.mark.nothing
failsonjython = pytest.mark.xfail("sys.platform.startswith('java')") failsonjython = pytest.mark.xfail("sys.platform.startswith('java')")
@ -227,7 +226,6 @@ class TestSourceParsingAndCompiling(object):
s = source.getstatement(1) s = source.getstatement(1)
assert s == str(source) assert s == str(source)
@astonly
def test_getstatementrange_within_constructs(self): def test_getstatementrange_within_constructs(self):
source = Source( source = Source(
"""\ """\
@ -630,7 +628,6 @@ x = 3
class TestTry(object): class TestTry(object):
pytestmark = astonly
source = """\ source = """\
try: try:
raise ValueError raise ValueError
@ -675,7 +672,6 @@ finally:
class TestIf(object): class TestIf(object):
pytestmark = astonly
source = """\ source = """\
if 1: if 1:
y = 3 y = 3

View File

@ -44,11 +44,11 @@ class TestMark(object):
class SomeClass(object): class SomeClass(object):
pass pass
assert pytest.mark.fun(some_function) is some_function assert pytest.mark.foo(some_function) is some_function
assert pytest.mark.fun.with_args(some_function) is not some_function assert pytest.mark.foo.with_args(some_function) is not some_function
assert pytest.mark.fun(SomeClass) is SomeClass assert pytest.mark.foo(SomeClass) is SomeClass
assert pytest.mark.fun.with_args(SomeClass) is not SomeClass assert pytest.mark.foo.with_args(SomeClass) is not SomeClass
def test_pytest_mark_name_starts_with_underscore(self): def test_pytest_mark_name_starts_with_underscore(self):
mark = Mark() mark = Mark()
@ -936,11 +936,11 @@ def test_mark_expressions_no_smear(testdir):
def test_addmarker_order(): def test_addmarker_order():
node = Node("Test", config=mock.Mock(), session=mock.Mock(), nodeid="Test") node = Node("Test", config=mock.Mock(), session=mock.Mock(), nodeid="Test")
node.add_marker("a") node.add_marker("foo")
node.add_marker("b") node.add_marker("bar")
node.add_marker("c", append=False) node.add_marker("baz", append=False)
extracted = [x.name for x in node.iter_markers()] extracted = [x.name for x in node.iter_markers()]
assert extracted == ["c", "a", "b"] assert extracted == ["baz", "foo", "bar"]
@pytest.mark.filterwarnings("ignore") @pytest.mark.filterwarnings("ignore")

View File

@ -141,7 +141,7 @@ commands = python scripts/release.py {posargs}
[pytest] [pytest]
minversion = 2.0 minversion = 2.0
addopts = -ra -p pytester addopts = -ra -p pytester --strict-markers
rsyncdirs = tox.ini doc src testing rsyncdirs = tox.ini doc src testing
python_files = test_*.py *_test.py testing/*/*.py python_files = test_*.py *_test.py testing/*/*.py
python_classes = Test Acceptance python_classes = Test Acceptance
@ -172,6 +172,11 @@ filterwarnings =
ignore::_pytest.warning_types.PytestUnknownMarkWarning ignore::_pytest.warning_types.PytestUnknownMarkWarning
pytester_example_dir = testing/example_scripts pytester_example_dir = testing/example_scripts
markers = markers =
# dummy markers for testing
foo
bar
baz
# conftest.py reorders tests moving slow ones to the end of the list
slow slow
[flake8] [flake8]