diff --git a/Doc/library/test.rst b/Doc/library/test.rst --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -400,16 +400,39 @@ The :mod:`test.support` module defines t otherwise. .. decorator:: skip_unless_symlink() A decorator for running tests that require support for symbolic links. +.. decorator:: skip_on_windows + skip_on_windows(reason='skipped on Windows') + + A decorator that will skip the decorated test on Windows. + + Raises :exc:`TypeError` if *reason* is not a :class:`str` object. + + Example usage:: + + class SpamTest(unittest.TestCase): + + @skip_on_windows + def test_spam(self): + # test something + + @skip_on_windows('cannot control directory permissions on Windows') + def test_eggs(self): + # test something else + + + .. versionadded:: 3.4 + + .. function:: suppress_crash_popup() A context manager that disables Windows Error Reporting dialogs using `SetErrorMode `_. On other platforms it's a no-op. .. decorator:: anticipate_failure(condition) diff --git a/Lib/test/support.py b/Lib/test/support.py --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -457,16 +457,30 @@ def requires_mac_ver(*min_version): "Mac OS X %s or higher required, not %s" % (min_version_txt, version_txt)) return func(*args, **kw) wrapper.min_version = min_version return wrapper return decorator +def skip_on_windows(test=None, reason='skipped on Windows'): + if not callable(test): + if not isinstance(test, str): + reason = 'reason must be a string, not {:s}' + raise TypeError(reason.format(type(test).__name__)) + return functools.partial(skip_on_windows, reason=test) + + @functools.wraps(test) + def wrapper(*args, **kwargs): + if sys.platform == 'win32': + raise unittest.SkipTest(reason) + return wrapper + + HOST = 'localhost' def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM): """Returns an unused port that should be suitable for binding. This is achieved by creating a temporary socket with the same family and type as the 'sock' parameter (default is AF_INET, SOCK_STREAM), and binding it to the specified host address (defaults to 0.0.0.0) with the port set to 0, eliciting an unused ephemeral port from the OS. The temporary socket is