diff --git a/changelog/5023.feature.rst b/changelog/5023.feature.rst index a4c67fe68..348e2f1c3 100644 --- a/changelog/5023.feature.rst +++ b/changelog/5023.feature.rst @@ -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 diff --git a/doc/en/reference.rst b/doc/en/reference.rst index 4b76bdaf7..33e4412ca 100644 --- a/doc/en/reference.rst +++ b/doc/en/reference.rst @@ -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`` @@ -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. diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 92e9395c7..a76797301 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -11,7 +11,6 @@ import textwrap import py import six from six.moves import queue -from test_source import astonly import _pytest import pytest @@ -147,7 +146,6 @@ class TestTraceback_f_g_h(object): assert s.startswith("def f():") assert s.endswith("raise ValueError") - @astonly @failsonjython def test_traceback_entry_getsource_in_construct(self): source = _pytest._code.Source( diff --git a/testing/code/test_source.py b/testing/code/test_source.py index aa56273c4..8d400a289 100644 --- a/testing/code/test_source.py +++ b/testing/code/test_source.py @@ -16,7 +16,6 @@ import _pytest._code import pytest from _pytest._code import Source -astonly = pytest.mark.nothing failsonjython = pytest.mark.xfail("sys.platform.startswith('java')") @@ -227,7 +226,6 @@ class TestSourceParsingAndCompiling(object): s = source.getstatement(1) assert s == str(source) - @astonly def test_getstatementrange_within_constructs(self): source = Source( """\ @@ -630,7 +628,6 @@ x = 3 class TestTry(object): - pytestmark = astonly source = """\ try: raise ValueError @@ -675,7 +672,6 @@ finally: class TestIf(object): - pytestmark = astonly source = """\ if 1: y = 3 diff --git a/testing/test_mark.py b/testing/test_mark.py index 03cd2f78c..b2f893438 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -44,11 +44,11 @@ class TestMark(object): 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() @@ -936,11 +936,11 @@ def test_mark_expressions_no_smear(testdir): 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") diff --git a/tox.ini b/tox.ini index e9517b63c..fb4134d17 100644 --- a/tox.ini +++ b/tox.ini @@ -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 @@ -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]