Python pytest挂起。例如,“pytest版本”只是挂起

2024-06-02 09:08:30 发布

您现在位置:Python中文网/ 问答频道 /正文

以下挂起:

PS C:\Users\Fowler> pytest --version  

注意事项:

  • 我在Windows10中。你知道吗
  • 我所说的挂起,是指至少5分钟等待pytest——版本返回。。。你知道吗
  • 在等待测试时,python.exe正在我的计算机上使用100%的逻辑处理器。你知道吗
  • 我用windows安装程序卸载了所有python安装,并重新安装了python3.8.0,试图修复这个问题。你知道吗
  • 只有当我没有使用venv时,pytest才会失败。因此,pytest是否使用venv工作。你知道吗
  • 但是,我不能将venv与vscode一起使用,因为使用venv进行调试会产生一个奇怪的“Session-1超时,等待debuggee生成”<;--您可能会认为debuggee这个词是一个很好的线索,但在google上找不到太多。我猜这是一个不同的问题,但可能相关?你知道吗
  • 总之,我不能用venv调试python,也不能在没有venv的情况下运行pytest单元测试。也许,这些东西是不相关的。。。但是,由于这第二十二条军规,我将非常感谢任何提示来解决这两个问题。你知道吗

当我点击<ctrl-c>打破pytest的“挂起”时,会显示以下内容(但每次结束时会有一点变化?地址:

Traceback (most recent call last):
  File "c:\program files\python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\program files\python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\Scripts\pytest.exe\__main__.py", line 7, in <module>
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\_pytest\config\__init__.py", line 72, in main
    config = _prepareconfig(args, plugins)
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\_pytest\config\__init__.py", line 222, in _prepareconfig
    return pluginmanager.hook.pytest_cmdline_parse(
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\pluggy\hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\pluggy\manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\pluggy\manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\pluggy\callers.py", line 203, in _multicall
    gen.send(outcome)
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\_pytest\helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\pluggy\callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\pluggy\callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\_pytest\config\__init__.py", line 742, in pytest_cmdline_parse
    self.parse(args)
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\_pytest\config\__init__.py", line 948, in parse
    self._preparse(args, addopts=addopts)
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\_pytest\config\__init__.py", line 896, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\pluggy\manager.py", line 299, in load_setuptools_entrypoints
    plugin = ep.load()
  File "c:\program files\python38\lib\importlib\metadata.py", line 75, in load
    module = import_module(match.group('module'))
  File "c:\program files\python38\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\_pytest\assertion\rewrite.py", line 138, in exec_module
    _write_pyc(state, co, source_stat, pyc)
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\_pytest\assertion\rewrite.py", line 274, in _write_pyc
    with atomic_write(fspath(pyc), mode="wb", overwrite=True) as fp:
  File "c:\program files\python38\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\atomicwrites\__init__.py", line 156, in _open
    with get_fileobject(**self._open_kwargs) as f:
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\atomicwrites\__init__.py", line 173, in get_fileobject
    descriptor, name = tempfile.mkstemp(suffix=suffix, prefix=prefix,
  File "c:\program files\python38\lib\tempfile.py", line 332, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags, output_type)
  File "c:\program files\python38\lib\tempfile.py", line 247, in _mkstemp_inner
    file = _os.path.join(dir, pre + name + suf)
KeyboardInterrupt

下次尝试运行pytest --version时,我按了<ctrl-c>,结果是:

Traceback (most recent call last):
  File "c:\program files\python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
...
...
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\atomicwrites\__init__.py", line 173, in get_fileobject
    descriptor, name = tempfile.mkstemp(suffix=suffix, prefix=prefix,
  File "c:\program files\python38\lib\tempfile.py", line 332, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags, output_type)
  File "c:\program files\python38\lib\tempfile.py", line 248, in _mkstemp_inner
    _sys.audit("tempfile.mkstemp", file)
KeyboardInterrupt

下次尝试运行pytest --version时,我按了<ctrl-c>,结果是:

Traceback (most recent call last):
  File "c:\program files\python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
...
...
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\atomicwrites\__init__.py", line 173, in get_fileobject
    descriptor, name = tempfile.mkstemp(suffix=suffix, prefix=prefix,
  File "c:\program files\python38\lib\tempfile.py", line 332, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags, output_type)
  File "c:\program files\python38\lib\tempfile.py", line 256, in _mkstemp_inner
    if (_os.name == 'nt' and _os.path.isdir(dir) and
  File "c:\program files\python38\lib\genericpath.py", line 42, in isdir
    st = os.stat(s)
KeyboardInterrupt

下次尝试运行pytest --version时,我按了<ctrl-c>,结果是:

Traceback (most recent call last):
  File "c:\program files\python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
...
...
  File "C:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\atomicwrites\__init__.py", line 173, in get_fileobject
    descriptor, name = tempfile.mkstemp(suffix=suffix, prefix=prefix,
  File "c:\program files\python38\lib\tempfile.py", line 332, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags, output_type)
  File "c:\program files\python38\lib\tempfile.py", line 250, in _mkstemp_inner
    fd = _os.open(file, flags, 0o600)
KeyboardInterrupt

我不知道这个输出是否有帮助,但我认为查看我的机器上安装python和/或pytest的所有位置可能会很有用:

PS C:\Users\Fowler> where.exe /r c:\ python
c:\Program Files\Amazon\AWSCLI\runtime\python.exe
c:\Program Files\Amazon\AWSSAMCLI\runtime\python.exe
c:\Program Files\MySQL\MySQL Workbench 8.0 CE\python.exe
c:\Program Files\Python38\python.exe
c:\Program Files\Python38\Lib\venv\scripts\nt\python.exe
c:\Users\Fowler\.vscode\extensions\lextudio.restructuredtext-116.0.0\out\python.js
c:\Users\Fowler\.vscode\extensions\teabyii.ayu-0.18.0\test\Python.py
c:\Users\Fowler\.vscode\extensions\yzane.markdown-pdf-1.4.1\node_modules\highlight.js\lib\languages\python.js
c:\Users\Fowler\AppData\Local\GitHubDesktop\app-2.2.2\resources\app\highlighter\mode\python.js
c:\Users\Fowler\AppData\Local\GitHubDesktop\app-2.2.3\resources\app\highlighter\mode\python.js
c:\Users\Fowler\AppData\Local\Google\Chrome\User Data\Default\Extensions\ngkhgikojglcgnckopipfdajaifmmnnc\4.1.34_0\python.js
c:\Users\Fowler\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\etc\apparmor.d\abstractions\python
c:\Users\Fowler\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\usr\share\bash-completion\completions\python
c:\Users\Fowler\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\usr\share\bash-completion\helpers\python
c:\Users\Fowler\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\usr\share\sosreport\sos\plugins\python.py
c:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\aniso8601\builders\python.py
c:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\_pytest\python.py
c:\Users\Fowler\Documents\vscodeProjects\playarea\.venv\Scripts\python.exe
c:\Windows\Installer\$PatchCache$\Managed\8B9C64EBE8DD53846B6846E46A14F5EE\3.7.2150\python.exe
c:\Windows\Installer\$PatchCache$\Managed\9CB0624238F6F8F469EAD6566412DD7F\3.7.2150\python.exe

PS C:\Users\Fowler> where.exe /r c:\ pytest
c:\Users\Fowler\AppData\Roaming\Python\Python38\Scripts\pytest.exe
c:\Users\Fowler\AppData\Roaming\Python\Python38\site-packages\pytest.py

最后呢!哦,如果这有什么问题的话,这里有一张图片显示了python进程在运行过程中消耗CPU的乐趣pytest.py测试... 你知道吗

Picture showing the python process running during pytest hang

如果有任何帮助或想法,我会非常感激的!你知道吗


Tags: inpypytestlibpackageslinesitefiles
1条回答
网友
1楼 · 发布于 2024-06-02 09:08:30

已修复。你知道吗

答案似乎是

  1. 通过windows应用程序和功能卸载python
  2. 删除c:\program files\python38目录
  3. 删除..\AppData\Roaming\Python目录
  4. 重新安装

不确定“根”问题是什么,但是彻底清除python就解决了这个问题。请注意,pythonwindows安装程序没有删除足够的python内容。你知道吗

谢谢你@nneonneo让我朝着正确的方向思考。你知道吗

相关问题 更多 >