gpt4 book ai didi

python - Py.test 收集阶段需要很长时间

转载 作者:行者123 更新时间:2023-12-03 20:20:51 26 4
gpt4 key购买 nike

一般来说,我对 Python 开发真的很陌生,更不用说用 pytest 进行测试了。我的问题是 pytest 收集阶段运行异常缓慢。我指定的测试目录只包含少量文件,其中只有一个文件包含三个测试。收集几乎需要整整一分钟,之后实际测试会在几秒钟内运行。我看过类似的问题,但找不到解决方案。我认为这并不重要(因为 py.test 即使从命令行也很慢),但我使用的是 pycharm IDE。操作系统是 Ubuntu。

这可能是相关的:如果我在几秒钟后终止进程,我通常会以堆栈跟踪结束,如下所示:

<A FEW LINES OMITTED...>
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 413, in __call__
return self._docall(methods, kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 424, in _docall
res = mc.execute()
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 315, in execute
res = method(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/helpconfig.py", line 27, in pytest_cmdline_parse
config = __multicall__.execute()
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 315, in execute
res = method(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 636, in pytest_cmdline_parse
self.parse(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 747, in parse
self._preparse(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 709, in _preparse
self._initini(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 704, in _initini
self.inicfg = getcfg(args, ["pytest.ini", "tox.ini", "setup.cfg"])
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 861, in getcfg
if exists(p):
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 848, in exists
return path.check()
File "/usr/local/lib/python2.7/dist-packages/py/_path/local.py", line 352, in check
return exists(self.strpath)
File "/usr/lib/python2.7/genericpath.py", line 18, in exists
os.stat(path)
KeyboardInterrupt

或者有时...
<STACK TRACE...>
File "/usr/local/lib/python2.7/dist-packages/py/_iniconfig.py", line 50, in __init__
f = open(self.path)
KeyboardInterrupt

也许 KeyboardInterrupt 之前的最后两个调用之一非常慢?

如果您需要,请询问更多详细信息!

干杯!

最佳答案

我有同样的问题。我的解决方法是设置 Working directory Run/Debug Configuration 中的设置到 manage.py 所在的文件夹位于。

关于python - Py.test 收集阶段需要很长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25329012/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com