diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index a6fcb1bc143784..c6cf8c6f9b2b1a 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -844,7 +844,11 @@ def dec(*args, **kwargs): '\u20AC', ): try: - os.fsdecode(os.fsencode(character)) + # If Python is set up to use the legacy 'mbcs' in Windows, + # 'replace' error mode is used, and encode() returns b'?' + # for characters missing in the ANSI codepage + if os.fsdecode(os.fsencode(character)) != character: + raise UnicodeError except UnicodeError: pass else: