[Python-checkins] cpython: Issue #10966: Remove the concept of unexpected skipped tests.

brett.cannon python-checkins at python.org
Sun Nov 18 02:47:12 CET 2012


http://hg.python.org/cpython/rev/eb3714863872
changeset:   80486:eb3714863872
parent:      80484:779e8f31dd30
user:        Brett Cannon <brett at python.org>
date:        Sat Nov 17 20:46:26 2012 -0500
summary:
  Issue #10966: Remove the concept of unexpected skipped tests.

The concept of what was unexpected was typically defined as "some
depencendy wasn't installed", which isn't unexpected at all as it's
totally optional. Since it confuses new contributors as they think
something is wrong with their installation it seems sensible to get
rid of the concept.

This change also adds the concept of optional tests that are required
to work on a specific platform(s) (e.g. test_winreg on Windows). This
should help catch compile issues instead of a test being blindly
skipped even when it should have run.

The skipped test list in the future can also print out the reason for
being skipped to make it more obvious as to why the skipping occurred.

files:
  Lib/test/regrtest.py    |  293 ----------------------------
  Lib/test/support.py     |   15 +-
  Lib/test/test_winreg.py |    2 +-
  Misc/NEWS               |    2 +
  4 files changed, 14 insertions(+), 298 deletions(-)


diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -763,20 +763,6 @@
         print(count(len(skipped), "test"), "skipped:")
         printlist(skipped)
 
-        e = _ExpectedSkips()
-        plat = sys.platform
-        if e.isvalid():
-            surprise = set(skipped) - e.getexpected() - set(resource_denieds)
-            if surprise:
-                print(count(len(surprise), "skip"), \
-                      "unexpected on", plat + ":")
-                printlist(surprise)
-            else:
-                print("Those skips are all expected on", plat + ".")
-        else:
-            print("Ask someone to teach regrtest.py about which tests are")
-            print("expected to get skipped on", plat + ".")
-
     if verbose2 and bad:
         print("Re-running failed tests in verbose mode")
         for test in bad:
@@ -1470,285 +1456,6 @@
     print(fill(' '.join(str(elt) for elt in sorted(x)), width,
                initial_indent=blanks, subsequent_indent=blanks))
 
-# Map sys.platform to a string containing the basenames of tests
-# expected to be skipped on that platform.
-#
-# Special cases:
-#     test_pep277
-#         The _ExpectedSkips constructor adds this to the set of expected
-#         skips if not os.path.supports_unicode_filenames.
-#     test_timeout
-#         Controlled by test_timeout.skip_expected.  Requires the network
-#         resource and a socket module.
-#
-# Tests that are expected to be skipped everywhere except on one platform
-# are also handled separately.
-
-_expectations = (
-    ('win32',
-        """
-        test__locale
-        test_crypt
-        test_curses
-        test_dbm
-        test_devpoll
-        test_fcntl
-        test_fork1
-        test_epoll
-        test_dbm_gnu
-        test_dbm_ndbm
-        test_grp
-        test_ioctl
-        test_largefile
-        test_kqueue
-        test_openpty
-        test_ossaudiodev
-        test_pipes
-        test_poll
-        test_posix
-        test_pty
-        test_pwd
-        test_resource
-        test_signal
-        test_syslog
-        test_threadsignals
-        test_wait3
-        test_wait4
-        """),
-    ('linux',
-        """
-        test_curses
-        test_devpoll
-        test_largefile
-        test_kqueue
-        test_ossaudiodev
-        """),
-    ('unixware',
-        """
-        test_epoll
-        test_largefile
-        test_kqueue
-        test_minidom
-        test_openpty
-        test_pyexpat
-        test_sax
-        test_sundry
-        """),
-    ('openunix',
-        """
-        test_epoll
-        test_largefile
-        test_kqueue
-        test_minidom
-        test_openpty
-        test_pyexpat
-        test_sax
-        test_sundry
-        """),
-    ('sco_sv',
-        """
-        test_asynchat
-        test_fork1
-        test_epoll
-        test_gettext
-        test_largefile
-        test_locale
-        test_kqueue
-        test_minidom
-        test_openpty
-        test_pyexpat
-        test_queue
-        test_sax
-        test_sundry
-        test_thread
-        test_threaded_import
-        test_threadedtempfile
-        test_threading
-        """),
-    ('darwin',
-        """
-        test__locale
-        test_curses
-        test_devpoll
-        test_epoll
-        test_dbm_gnu
-        test_gdb
-        test_largefile
-        test_locale
-        test_minidom
-        test_ossaudiodev
-        test_poll
-        """),
-    ('sunos',
-        """
-        test_curses
-        test_dbm
-        test_epoll
-        test_kqueue
-        test_dbm_gnu
-        test_gzip
-        test_openpty
-        test_zipfile
-        test_zlib
-        """),
-    ('hp-ux',
-        """
-        test_curses
-        test_epoll
-        test_dbm_gnu
-        test_gzip
-        test_largefile
-        test_locale
-        test_kqueue
-        test_minidom
-        test_openpty
-        test_pyexpat
-        test_sax
-        test_zipfile
-        test_zlib
-        """),
-    ('cygwin',
-        """
-        test_curses
-        test_dbm
-        test_devpoll
-        test_epoll
-        test_ioctl
-        test_kqueue
-        test_largefile
-        test_locale
-        test_ossaudiodev
-        test_socketserver
-        """),
-    ('freebsd',
-        """
-        test_devpoll
-        test_epoll
-        test_dbm_gnu
-        test_locale
-        test_ossaudiodev
-        test_pep277
-        test_pty
-        test_socketserver
-        test_tcl
-        test_tk
-        test_ttk_guionly
-        test_ttk_textonly
-        test_timeout
-        test_urllibnet
-        test_multiprocessing
-        """),
-    ('aix',
-        """
-        test_bz2
-        test_epoll
-        test_dbm_gnu
-        test_gzip
-        test_kqueue
-        test_ossaudiodev
-        test_tcl
-        test_tk
-        test_ttk_guionly
-        test_ttk_textonly
-        test_zipimport
-        test_zlib
-        """),
-    ('openbsd',
-        """
-        test_ctypes
-        test_devpoll
-        test_epoll
-        test_dbm_gnu
-        test_locale
-        test_normalization
-        test_ossaudiodev
-        test_pep277
-        test_tcl
-        test_tk
-        test_ttk_guionly
-        test_ttk_textonly
-        test_multiprocessing
-        """),
-    ('netbsd',
-        """
-        test_ctypes
-        test_curses
-        test_devpoll
-        test_epoll
-        test_dbm_gnu
-        test_locale
-        test_ossaudiodev
-        test_pep277
-        test_tcl
-        test_tk
-        test_ttk_guionly
-        test_ttk_textonly
-        test_multiprocessing
-        """),
-)
-
-class _ExpectedSkips:
-    def __init__(self):
-        import os.path
-        from test import test_timeout
-
-        self.valid = False
-        expected = None
-        for item in _expectations:
-            if sys.platform.startswith(item[0]):
-                expected = item[1]
-                break
-        if expected is not None:
-            self.expected = set(expected.split())
-
-            # These are broken tests, for now skipped on every platform.
-            # XXX Fix these!
-            self.expected.add('test_nis')
-
-            # expected to be skipped on every platform, even Linux
-            if not os.path.supports_unicode_filenames:
-                self.expected.add('test_pep277')
-
-            # doctest, profile and cProfile tests fail when the codec for the
-            # fs encoding isn't built in because PyUnicode_Decode() adds two
-            # calls into Python.
-            encs = ("utf-8", "latin-1", "ascii", "mbcs", "utf-16", "utf-32")
-            if sys.getfilesystemencoding().lower() not in encs:
-                self.expected.add('test_profile')
-                self.expected.add('test_cProfile')
-                self.expected.add('test_doctest')
-
-            if test_timeout.skip_expected:
-                self.expected.add('test_timeout')
-
-            if sys.platform != "win32":
-                # test_sqlite is only reliable on Windows where the library
-                # is distributed with Python
-                WIN_ONLY = {"test_unicode_file", "test_winreg",
-                            "test_winsound", "test_startfile",
-                            "test_sqlite", "test_msilib"}
-                self.expected |= WIN_ONLY
-
-            if sys.platform != 'sunos5':
-                self.expected.add('test_nis')
-
-            if support.python_is_optimized():
-                self.expected.add("test_gdb")
-
-            self.valid = True
-
-    def isvalid(self):
-        "Return true iff _ExpectedSkips knows about the current platform."
-        return self.valid
-
-    def getexpected(self):
-        """Return set of test names we expect to skip on current platform.
-
-        self.isvalid() must be true.
-        """
-
-        assert self.isvalid()
-        return self.expected
 
 def _make_temp_dir_for_build(TEMPDIR):
     # When tests are run from the Python build directory, it is best practice
diff --git a/Lib/test/support.py b/Lib/test/support.py
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -93,7 +93,8 @@
     """Context manager to suppress package and module deprecation
     warnings when importing them.
 
-    If ignore is False, this context manager has no effect."""
+    If ignore is False, this context manager has no effect.
+    """
     if ignore:
         with warnings.catch_warnings():
             warnings.filterwarnings("ignore", ".+ (module|package)",
@@ -103,23 +104,29 @@
         yield
 
 
-def import_module(name, deprecated=False):
+def import_module(name, deprecated=False, *, required_on=()):
     """Import and return the module to be tested, raising SkipTest if
     it is not available.
 
     If deprecated is True, any module or package deprecation messages
-    will be suppressed."""
+    will be suppressed. If a module is required on a platform but optional for
+    others, set required_on to an iterable of platform prefixes which will be
+    compared against sys.platform.
+    """
     with _ignore_deprecated_imports(deprecated):
         try:
             return importlib.import_module(name)
         except ImportError as msg:
+            if sys.platform.startswith(tuple(required_on)):
+                raise
             raise unittest.SkipTest(str(msg))
 
 
 def _save_and_remove_module(name, orig_modules):
     """Helper function to save and remove a module from sys.modules
 
-       Raise ImportError if the module can't be imported."""
+       Raise ImportError if the module can't be imported.
+       """
     # try to import the module and raise an error if it can't be imported
     if name not in sys.modules:
         __import__(name)
diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py
--- a/Lib/test/test_winreg.py
+++ b/Lib/test/test_winreg.py
@@ -8,7 +8,7 @@
 from platform import machine
 
 # Do this first so test will be skipped if module doesn't exist
-support.import_module('winreg')
+support.import_module('winreg', required_on=['win'])
 # Now import everything
 from winreg import *
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -423,6 +423,8 @@
 Tools/Demos
 -----------
 
+- Issue #10966: Remove the concept of unexpected skipped tests.
+
 - Issue #9893: Removed the Misc/Vim directory.
 
 - Removed the Misc/TextMate directory.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list