diff options
Diffstat (limited to 'Lib/test/support/__init__.py')
-rw-r--r-- | Lib/test/support/__init__.py | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 7e5a29b18d..51af6f37d9 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1525,9 +1525,8 @@ def check_sizeof(test, o, size): # Decorator for running a function in a different locale, correctly resetting # it afterwards. +@contextlib.contextmanager def run_with_locale(catstr, *locales): - def decorator(func): - def inner(*args, **kwds): try: import locale category = getattr(locale, catstr) @@ -1546,16 +1545,11 @@ def run_with_locale(catstr, *locales): except: pass - # now run the function, resetting the locale on exceptions try: - return func(*args, **kwds) + yield finally: if locale and orig_locale: locale.setlocale(category, orig_locale) - inner.__name__ = func.__name__ - inner.__doc__ = func.__doc__ - return inner - return decorator #======================================================================= # Decorator for running a function in a specific timezone, correctly |