diff --git a/traits-stubs/traits_stubs_tests/test_all.py b/traits-stubs/traits_stubs_tests/test_all.py index 17a56f864..7d92b9fc1 100644 --- a/traits-stubs/traits_stubs_tests/test_all.py +++ b/traits-stubs/traits_stubs_tests/test_all.py @@ -14,9 +14,11 @@ import pkg_resources +from traits.testing.optional_dependencies import requires_mypy from traits_stubs_tests.util import MypyAssertions +@requires_mypy class TestAnnotations(TestCase, MypyAssertions): def test_all(self, filename_suffix=''): """ Run mypy for all files contained in traits_stubs_tests/examples diff --git a/traits-stubs/traits_stubs_tests/util.py b/traits-stubs/traits_stubs_tests/util.py index cb46fc76a..063e489ba 100644 --- a/traits-stubs/traits_stubs_tests/util.py +++ b/traits-stubs/traits_stubs_tests/util.py @@ -15,8 +15,6 @@ import re import tempfile -from mypy import api as mypy_api - def parse_py_file(filepath): """ This function parses a python file that have been annotated with error @@ -98,6 +96,9 @@ def run_mypy(filepath): The exit status """ + # Local import to make it easier to skip tests if mypy is not in + # the environment. + from mypy import api as mypy_api # Need to use tempdir since mypy complains that: # "site-packages is in PYTHONPATH. Please change directory so it is not." diff --git a/traits/testing/optional_dependencies.py b/traits/testing/optional_dependencies.py index 59f61d8d2..94b820163 100644 --- a/traits/testing/optional_dependencies.py +++ b/traits/testing/optional_dependencies.py @@ -39,6 +39,9 @@ def optional_import(name): cython = optional_import("cython") requires_cython = unittest.skipIf(cython is None, "Cython not available") +mypy = optional_import("mypy") +requires_mypy = unittest.skipIf(mypy is None, "Mypy not available") + numpy = optional_import("numpy") requires_numpy = unittest.skipIf(numpy is None, "NumPy not available")