pytest(py.test)在cygwin中启动非常慢

pytest(py.test)在cygwin中启动非常慢,第1张

pytest(py.test)在cygwin中启动非常慢

问题是对于pytest搜索

//pytest.ini
//tox.ini
//setup.cfg
,和
//setup.py
。他们每个人造成
genericpath.exists()
genericpath.isfile()
消耗了大约2.5秒。

解决的办法是在下面添加以下行,

genericpath.exists()
genericpath.isfile()
跳过这四个特定路径

if path.startswith(r'//'):    return False

另一种解决方法是修改

_pytest/config.py
,使其不会在搜索路径中形成双斜杠

用于查找确切问题的代码粘贴在下面。进行设置

myshow = True
以显示要搜索的每个文件的时间消耗。

$ diff -u /usr/lib/python2.6/genericpath.py genericpath.py--- /usr/lib/python2.6/genericpath.py   2012-06-09 08:33:12.000000000 -0700+++ genericpath.py      2015-06-11 11:46:33.674285900 -0700@@ -9,14 +9,29 @@ __all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime', 'getsize', 'isdir', 'isfile']+myshow = False+import time as mytime+mybasetime = mytime.time()+def myshowtime():+    currenttime = mytime.time()+    tmdiff = currenttime - mybasetime+    global mybasetime+    mybasetime = currenttime+    return tmdiff # Does a path exist? # This is false for dangling symbolic links on systems that support them. def exists(path):     """Test whether a path exists.  Returns False for broken symbolic links"""+    pretime = myshowtime()+    if path.startswith(r'//'):+        if myshow: print "n  genericpath exists  %8.3f %8.3f False " % (pretime, myshowtime()), " ", path, "n"+        return False     try:         st = os.stat(path)+        if myshow: print "n  genericpath exists  %8.3f %8.3f True  " % (pretime, myshowtime()), " ", path, "n"     except os.error:+        if myshow: print "n  genericpath exists  %8.3f %8.3f False " % (pretime, myshowtime()), " ", path, "n"         return False     return True@@ -25,9 +40,15 @@ # for the same path ono systems that support symlinks def isfile(path):     """Test whether a path is a regular file"""+    pretime = myshowtime()+    if path.startswith(r'//'):+        if myshow: print "n  genericpath isfile  %8.3f %8.3f False " % (pretime, myshowtime()), " ", path, "n"+        return False     try:         st = os.stat(path)+        if myshow: print "n  genericpath isfile  %8.3f %8.3f True  " % (pretime, myshowtime()), " ", path, "n"     except os.error:+        if myshow: print "n  genericpath isfile  %8.3f %8.3f False " % (pretime, myshowtime()), " ", path, "n"         return False     return stat.S_ISREG(st.st_mode)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5664212.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存