diff --git a/.flake8 b/.flake8 index c57b2e68402..66bc1cf29c0 100644 --- a/.flake8 +++ b/.flake8 @@ -171,7 +171,6 @@ exclude = numba/tests/test_extended_arg.py numba/tests/test_alignment.py numba/tests/test_multi3.py - numba/tests/test_import.py numba/tests/test_overlap.py numba/tests/test_array_attr.py numba/tests/test_array_methods.py diff --git a/numba/tests/test_import.py b/numba/tests/test_import.py index 2d8fff741e7..7fdf394dd87 100644 --- a/numba/tests/test_import.py +++ b/numba/tests/test_import.py @@ -1,8 +1,8 @@ +import unittest import subprocess import sys from numba.tests.support import TestCase -import unittest class TestNumbaImport(TestCase): @@ -10,22 +10,33 @@ class TestNumbaImport(TestCase): Test behaviour of importing Numba. """ + def run_in_subproc(self, code, flags=None): + if flags is None: + flags = [] + cmd = [sys.executable,] + flags + ["-c", code] + popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = popen.communicate() + if popen.returncode != 0: + msg = "process failed with code %s: stderr follows\n%s\n" + raise AssertionError(msg % (popen.returncode, err.decode())) + return out, err + def test_laziness(self): """ Importing top-level numba features should not import too many modules. """ # A heuristic set of modules that shouldn't be imported immediately - blacklist = [ - 'cffi', - 'distutils', - 'numba.cuda', - 'numba.cpython.mathimpl', - 'numba.cpython.randomimpl', - 'numba.tests', - 'numba.core.typing.collections', - 'numba.core.typing.listdecl', - 'numba.core.typing.npdatetime', - ] + blacklist = ['cffi', + 'distutils', + 'numba.cuda', + 'numba.cpython.mathimpl', + 'numba.cpython.randomimpl', + 'numba.tests', + 'numba.core.typing.collections', + 'numba.core.typing.listdecl', + 'numba.core.typing.npdatetime', + ] # Sanity check the modules still exist... for mod in blacklist: if mod not in ('cffi',): @@ -38,13 +49,18 @@ def test_laziness(self): print(list(sys.modules)) """ - popen = subprocess.Popen([sys.executable, "-c", code], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = popen.communicate() - if popen.returncode != 0: - raise AssertionError("process failed with code %s: stderr follows\n%s\n" - % (popen.returncode, err.decode())) - + out, _ = self.run_in_subproc(code) modlist = set(eval(out.strip())) unexpected = set(blacklist) & set(modlist) self.assertFalse(unexpected, "some modules unexpectedly imported") + + def test_no_accidental_warnings(self): + # checks that importing Numba isn't accidentally triggering warnings due + # to e.g. deprecated use of import locations from Python's stdlib + code = "import numba" + flags = ["-Werror",] + self.run_in_subproc(code, flags) + + +if __name__ == '__main__': + unittest.main()