@importorskip('PIL')
@importorskip(modname_tkinter)
@skip(reason='"excludedimports" support is non-deterministically broken.')
def test_pil_no_tkinter(pyi_builder):
 pyi_builder.test_source('\n        import PIL.Image\n\n        # Dynamically importing the Tkinter package should fail with an\n        # "ImportError", implying "PIL" package hooks successfully excluded\n        # Tkinter. To prevent PyInstaller from parsing this import and thus\n        # freezing this extension with this test, this import is dynamic.\n        try:\n            __import__(\'{modname_tkinter}\')\n            raise SystemExit(\'ERROR: Module {modname_tkinter} is bundled.\')\n        except ImportError:\n            pass\n\n        # Dynamically importing the "_tkinter" shared library should also fail.\n        try:\n            __import__(\'_tkinter\')\n            raise SystemExit(\'ERROR: Module _tkinter is bundled.\')\n        except ImportError:\n            pass\n        '.format(modname_tkinter=modname_tkinter))

@ importorskip ( 'PIL' ) @ importorskip ( modname_tkinter ) @ skip ( reason = '"excludedimports" support is non-deterministically broken.' ) def test_pil_no_tkinter ( pyi_builder ) : pyi_builder . test_source ( '\n        import PIL.Image\n\n        # Dynamically importing the Tkinter package should fail with an\n        # "ImportError", implying "PIL" package hooks successfully excluded\n        # Tkinter. To prevent PyInstaller from parsing this import and thus\n        # freezing this extension with this test, this import is dynamic.\n        try:\n            __import__(\'{modname_tkinter}\')\n            raise SystemExit(\'ERROR: Module {modname_tkinter} is bundled.\')\n        except ImportError:\n            pass\n\n        # Dynamically importing the "_tkinter" shared library should also fail.\n        try:\n            __import__(\'_tkinter\')\n            raise SystemExit(\'ERROR: Module _tkinter is bundled.\')\n        except ImportError:\n            pass\n        ' . format ( modname_tkinter = modname_tkinter ) )
ensure that the tkinter package excluded by pil package hooks is unimportable by frozen applications explicitly importing only the latter .