Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第二次运行 pytest 出错:_tkinter.TclError: Can't find a usable init.tcl in the following directories: #49

Closed
1 task done
Snoopy1866 opened this issue Nov 10, 2024 · 4 comments
Labels
🐞 Bug Damn! Something isn't working! ❌ Wontfix Unfortunately, this will not be worked on.

Comments

@Snoopy1866
Copy link

Snoopy1866 commented Nov 10, 2024

Version

Latest development version

Platform

Windows 11

What Happened

第一次运行 pytest 都通过测试。
第二次运行 pytest 出现部分测试失败。

已经尝试过:

  • 重建 .venv 环境
  • 切换到 python 3.12.7
  • 在非虚拟环境中执行 pytest
  • 重装 python 3.12.7 到 D 盘,防止产生权限问题
  • 设置环境变量 TCL_LIBRARY = D:/Python/Python312/tcl/tcl8.6
  • 在系统自带命令提示符窗口而不是 vscode 默认终端中执行 pytest

Relevant Log Output

PS C:\Users\17531\Documents\GitHub\Snoopy1866\tkintertools> pytest
======================================================================================================== test session starts =========================================================================================================
platform win32 -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0
rootdir: C:\Users\17531\Documents\GitHub\Snoopy1866\tkintertools
configfile: pyproject.toml
collected 36 items                                                                                                                                                                                                                    

tests\test_animation\test_contollers.py ....                                                                                                                                                                                    [ 11%]
tests\test_color\test_colormap.py .                                                                                                                                                                                             [ 13%]
tests\test_color\test_hsl.py ........                                                                                                                                                                                           [ 36%]
tests\test_color\test_rgb.py .........                                                                                                                                                                                          [ 61%]
tests\test_theme\test_dark.py ..                                                                                                                                                                                                [ 66%]
tests\test_theme\test_light.py ..                                                                                                                                                                                               [ 72%]
tests\test_toolbox\test_enhanced.py ..                                                                                                                                                                                          [ 77%]
tests\test_toolbox\test_tools.py ........                                                                                                                                                                                       [100%]

========================================================================================================= 36 passed in 0.33s =========================================================================================================
PS C:\Users\17531\Documents\GitHub\Snoopy1866\tkintertools> pytest
======================================================================================================== test session starts =========================================================================================================
platform win32 -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0
rootdir: C:\Users\17531\Documents\GitHub\Snoopy1866\tkintertools
configfile: pyproject.toml
collected 36 items                                                                                                                                                                                                                    

tests\test_animation\test_contollers.py ....                                                                                                                                                                                    [ 11%]
tests\test_color\test_colormap.py .                                                                                                                                                                                             [ 13%]
tests\test_color\test_hsl.py ........                                                                                                                                                                                           [ 36%]
tests\test_color\test_rgb.py .........                                                                                                                                                                                          [ 61%]
tests\test_theme\test_dark.py ..                                                                                                                                                                                                [ 66%]
tests\test_theme\test_light.py ..                                                                                                                                                                                               [ 72%]
tests\test_toolbox\test_enhanced.py F.                                                                                                                                                                                          [ 77%]
tests\test_toolbox\test_tools.py ........                                                                                                                                                                                       [100%]

============================================================================================================== FAILURES ==============================================================================================================
_____________________________________________________________________________________________________ TestPhotoImage.test_resize _____________________________________________________________________________________________________ 

self = <tests.test_toolbox.test_enhanced.TestPhotoImage testMethod=test_resize>

    def setUp(self) -> None:
>       self.tk = tkinter.Tk()

tests\test_toolbox\test_enhanced.py:17:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

self = <tkinter.Tk object .>, screenName = None, baseName = 'pytest', className = 'Tk', useTk = True, sync = False, use = None

    def __init__(self, screenName=None, baseName=None, className='Tk',
                 useTk=True, sync=False, use=None):
        """Return a new top level widget on screen SCREENNAME. A new Tcl interpreter will
        be created. BASENAME will be used for the identification of the profile file (see
        readprofile).
        It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME
        is the name of the widget class."""
        self.master = None
        self.children = {}
        self._tkloaded = False
        # to avoid recursions in the getattr code in case of failure, we
        # ensure that self.tk is always _something_.
        self.tk = None
        if baseName is None:
            import os
            baseName = os.path.basename(sys.argv[0])
            baseName, ext = os.path.splitext(baseName)
            if ext not in ('.py', '.pyc'):
                baseName = baseName + ext
        interactive = False
>       self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
E       _tkinter.TclError: Can't find a usable init.tcl in the following directories: 
E           {D:\Python\Python312\tcl\tcl8.6}
E       
E       D:/Python/Python312/tcl/tcl8.6/init.tcl: couldn't read file "D:/Python/Python312/tcl/tcl8.6/init.tcl": No error
E       couldn't read file "D:/Python/Python312/tcl/tcl8.6/init.tcl": No error
E           while executing
E       "source D:/Python/Python312/tcl/tcl8.6/init.tcl"
E           ("uplevel" body line 1)
E           invoked from within
E       "uplevel #0 [list source $tclfile]"
E       
E       
E       This probably means that Tcl wasn't installed properly.

D:\Python\Python312\Lib\tkinter\__init__.py:2346: TclError
====================================================================================================== short test summary info ======================================================================================================= 
FAILED tests/test_toolbox/test_enhanced.py::TestPhotoImage::test_resize - _tkinter.TclError: Can't find a usable init.tcl in the following directories:
==================================================================================================== 1 failed, 35 passed in 0.34s ====================================================================================================

Extra Information

  • 我只是简单 clone 到本地,安装 pyproject.toml 中的 all 依赖,再安装 pylint 和 pytest,然后直接运行 pytest,未修改任何代码。
  • init.tcl 存在:
    image

Contact Details

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Snoopy1866 Snoopy1866 added the 🐞 Bug Damn! Something isn't working! label Nov 10, 2024
@Snoopy1866 Snoopy1866 changed the title 第二运行 pytest 出错 第二运行 pytest 出错:_tkinter.TclError: Can't find a usable init.tcl in the following directories: Nov 10, 2024
@Xiaokang2022
Copy link
Owner

见:python/cpython#126549 (comment)

CPython 背锅,与我无瓜(喜)。

@Xiaokang2022 Xiaokang2022 added the ❌ Wontfix Unfortunately, this will not be worked on. label Nov 10, 2024
@Xiaokang2022
Copy link
Owner

Xiaokang2022 commented Nov 10, 2024

可能与 pytest 也有一定的关系,因为直接运行 tests/__main__.py 是不会产生任何的报错,多次运行也是一样的。

直接运行 tests/__main__.py 属于是直接使用 unittest 进行测试,没有使用 pytest。(这里用 pytest 就只是为了输出好看一些)而且 workflow 也只运行一遍,所以嘛,问题不大!

如果后续 workflow 真的出现了一些比较大的问题,切换成直接使用 unittest 测试即可。

@Snoopy1866
Copy link
Author

好好好,我直接用 vscode 配置 unittest 批量测试就好了。

@Snoopy1866 Snoopy1866 changed the title 第二运行 pytest 出错:_tkinter.TclError: Can't find a usable init.tcl in the following directories: 第二次运行 pytest 出错:_tkinter.TclError: Can't find a usable init.tcl in the following directories: Nov 10, 2024
@Xiaokang2022
Copy link
Owner

好好好,我直接用 vscode 配置 unittest 批量测试就好了。

不用配置啊,直接打开 tests/__main__.py 然后运行这个文件即可自动测试全部内容(可以通过命令行运行,也可以直接运行这个文件,会自动查找全部的测试)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug Damn! Something isn't working! ❌ Wontfix Unfortunately, this will not be worked on.
Projects
None yet
Development

No branches or pull requests

2 participants