diff -r d9a1a2eb3069 Lib/test/support.py --- a/Lib/test/support.py Thu Mar 31 13:11:40 2011 -0400 +++ b/Lib/test/support.py Thu Mar 31 15:43:56 2011 -0500 @@ -27,6 +27,11 @@ import _thread except ImportError: _thread = None + +try: + import winreg +except ImportError: + winreg = None __all__ = [ "Error", "TestFailed", "ResourceDenied", "import_module", @@ -43,7 +48,8 @@ "run_unittest", "run_doctest", "threading_setup", "threading_cleanup", "reap_children", "cpython_only", "check_impl_detail", "get_attribute", "swap_item", "swap_attr", "requires_IEEE_754", - "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink"] + "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink", + "skip_unless_attended"] class Error(Exception): @@ -1517,3 +1523,45 @@ # actually override the attribute setattr(object_to_patch, attr_name, new_value) + +def skip_unless_unattended(test): + """Skip decorator used for tests which require manual intervention. + + Some tests, such as those in test_faulthandler, require subprocesses to + crash, but because of that they introduce the need for a user to manually + intervene in order to continue the test suite. Windows Error Reporting + displays a dialog to debug or send crash reports in these events, but + build slaves disable this in order to keep operating. A typical user's + desktop will have these dialogs enabled, thus interrupting their test run. + + This decorator skips tests whenever WER is enabled, so it only has an + effect on Windows OSes. + """ + if not winreg: + return test + + # Windows XP/2003 use the following locations + xp_subkey = "Software\Microsoft\PCHealth\ErrorReporting" + xp_value = "ShowUI" + # Windows Vista/7 now use WER and reversed the value + new_subkey = "Software\Microsoft\Windows\Windows Error Reporting" + new_value = "DontShowUI" + + configs = [(winreg.HKEY_CURRENT_USER, new_subkey, new_value, 1), + (winreg.HKEY_LOCAL_MACHINE, new_subkey, new_value, 1), + (winreg.HKEY_LOCAL_MACHINE, xp_subkey, xp_value, 0)] + + unattended = False + for key, subkey, val_name, value in configs: + try: + with winreg.OpenKey(key, subkey) as handle: + result, type = winreg.QueryValueEx(handle, val_name) + if type is not winreg.REG_DWORD: + break + if result == value: + unattended = True + break + except WindowsError: + pass + + return test if unattended else unittest.skip("Disruptive test")(test)