Skip to content

Commit

Permalink
Remove unused markers and enable --strict-markers
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed May 9, 2019
1 parent f1183c2 commit 0594dba
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
6 changes: 5 additions & 1 deletion changelog/5023.feature.rst
Original file line number Diff line number Diff line change
@@ -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
7 changes: 2 additions & 5 deletions doc/en/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1261,8 +1261,8 @@ passed multiple times. The expected format is ``name=value``. For example::

.. confval:: markers

When the ``--strict-markers`` command-line argument is used, only known markers -
defined in code by core pytest or some plugin - are allowed.
When the ``--strict-markers`` or ``--strict`` command-line arguments are used,
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,
in which case you probably want to add ``--strict-markers`` to ``addopts``
Expand All @@ -1276,9 +1276,6 @@ passed multiple times. The expected format is ``name=value``. For example::
slow
serial
**Note**: This option was previously called ``--strict``, which is now an
alias preserved for backward compatibility.

.. confval:: minversion

Specifies a minimal pytest version required for running tests.
Expand Down
2 changes: 0 additions & 2 deletions testing/code/test_excinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import py
import six
from six.moves import queue
from test_source import astonly

import _pytest
import pytest
Expand Down Expand Up @@ -147,7 +146,6 @@ def test_traceback_entry_getsource(self):
assert s.startswith("def f():")
assert s.endswith("raise ValueError")

@astonly
@failsonjython
def test_traceback_entry_getsource_in_construct(self):
source = _pytest._code.Source(
Expand Down
4 changes: 0 additions & 4 deletions testing/code/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import pytest
from _pytest._code import Source

astonly = pytest.mark.nothing
failsonjython = pytest.mark.xfail("sys.platform.startswith('java')")


Expand Down Expand Up @@ -227,7 +226,6 @@ def test_getstatementrange_triple_quoted(self):
s = source.getstatement(1)
assert s == str(source)

@astonly
def test_getstatementrange_within_constructs(self):
source = Source(
"""\
Expand Down Expand Up @@ -630,7 +628,6 @@ def test_multiline():


class TestTry(object):
pytestmark = astonly
source = """\
try:
raise ValueError
Expand Down Expand Up @@ -675,7 +672,6 @@ def test_finally(self):


class TestIf(object):
pytestmark = astonly
source = """\
if 1:
y = 3
Expand Down
16 changes: 8 additions & 8 deletions testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def some_function(abc):
class SomeClass(object):
pass

assert pytest.mark.fun(some_function) is some_function
assert pytest.mark.fun.with_args(some_function) is not some_function
assert pytest.mark.foo(some_function) is some_function
assert pytest.mark.foo.with_args(some_function) is not some_function

assert pytest.mark.fun(SomeClass) is SomeClass
assert pytest.mark.fun.with_args(SomeClass) is not SomeClass
assert pytest.mark.foo(SomeClass) is SomeClass
assert pytest.mark.foo.with_args(SomeClass) is not SomeClass

def test_pytest_mark_name_starts_with_underscore(self):
mark = Mark()
Expand Down Expand Up @@ -936,11 +936,11 @@ class TestBarClass(BaseTests):

def test_addmarker_order():
node = Node("Test", config=mock.Mock(), session=mock.Mock(), nodeid="Test")
node.add_marker("a")
node.add_marker("b")
node.add_marker("c", append=False)
node.add_marker("foo")
node.add_marker("bar")
node.add_marker("baz", append=False)
extracted = [x.name for x in node.iter_markers()]
assert extracted == ["c", "a", "b"]
assert extracted == ["baz", "foo", "bar"]


@pytest.mark.filterwarnings("ignore")
Expand Down
7 changes: 6 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ commands = python scripts/release.py {posargs}

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

[flake8]
Expand Down

0 comments on commit 0594dba

Please sign in to comment.