From 46f8b57c8b34484236ce1bc9aa9f5ea5fc77c5df Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Tue, 6 Aug 2019 22:09:40 -0700 Subject: [PATCH] Updating `@slow` marker for `pytest`. The old method (using the `pytest.config` global) is deprecated. For reference: https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option https://docs.pytest.org/en/latest/deprecations.html#pytest-config-global https://docs.pytest.org/en/latest/mark.html --- tests/conftest.py | 23 +++++++++++++++++++++++ tests/unit/test__surface_helpers.py | 20 +++++--------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0ade7b16..68b39a17 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,8 +22,14 @@ import sys import unittest +import pytest import six +try: + from bezier import _HAS_SPEEDUP as HAS_SPEEDUP +except ImportError: # pragma: NO COVER + HAS_SPEEDUP = False + if six.PY2: import mock # pylint: disable=import-error @@ -38,3 +44,20 @@ def pytest_addoption(parser): action="store_true", help="Ignore slow tests.", ) + + +def pytest_configure(config): + config.addinivalue_line("markers", "slow: mark test as slow to run") + + +def pytest_collection_modifyitems(config, items): + if not config.getoption("--ignore-slow"): + return + + if HAS_SPEEDUP: + return + + skip_slow = pytest.mark.skip(reason="--ignore-slow ignores the slow tests") + for item in items: + if "slow" in item.keywords: + item.add_marker(skip_slow) diff --git a/tests/unit/test__surface_helpers.py b/tests/unit/test__surface_helpers.py index 880ebc42..71e3856a 100644 --- a/tests/unit/test__surface_helpers.py +++ b/tests/unit/test__surface_helpers.py @@ -15,21 +15,11 @@ import numpy as np import pytest -try: - from bezier import _HAS_SPEEDUP as HAS_SPEEDUP -except ImportError: # pragma: NO COVER - HAS_SPEEDUP = False from tests.unit import utils UNIT_TRIANGLE = np.asfortranarray([[0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]) FLOAT64 = np.float64 # pylint: disable=no-member SPACING = np.spacing # pylint: disable=no-member -# pylint: disable=invalid-name,no-member -slow = pytest.mark.skipif( - pytest.config.getoption("--ignore-slow") and not HAS_SPEEDUP, - reason="--ignore-slow ignores the slow tests", -) -# pylint: enable=invalid-name,no-member class Test_polynomial_sign(unittest.TestCase): @@ -503,7 +493,7 @@ def test_linear(self): UNIT_TRIANGLE, 1, expected_a, expected_b, expected_c, expected_d ) - @slow + @pytest.mark.slow def test_line_check_evaluate(self): # Use a fixed seed so the test is deterministic and round # the nodes to 8 bits of precision to avoid round-off. @@ -540,7 +530,7 @@ def test_quadratic(self): ) self._helper(nodes, 2, expected_a, expected_b, expected_c, expected_d) - @slow + @pytest.mark.slow def test_quadratic_check_evaluate(self): # Use a fixed seed so the test is deterministic and round # the nodes to 8 bits of precision to avoid round-off. @@ -668,21 +658,21 @@ def test_cubic(self): ) self._helper(nodes, 3, expected_a, expected_b, expected_c, expected_d) - @slow + @pytest.mark.slow def test_cubic_check_evaluate(self): # Use a fixed seed so the test is deterministic and round # the nodes to 8 bits of precision to avoid round-off. nodes = utils.get_random_nodes(shape=(2, 10), seed=346323, num_bits=8) self._points_check(nodes, 3) - @slow + @pytest.mark.slow def test_quartic_check_evaluate(self): # Use a fixed seed so the test is deterministic and round # the nodes to 8 bits of precision to avoid round-off. nodes = utils.get_random_nodes(shape=(2, 15), seed=741002, num_bits=8) self._points_check(nodes, 4) - @slow + @pytest.mark.slow def test_on_the_fly(self): # Test for a degree where the subdivision is done on the fly # rather than via a stored matrix.