栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/662255.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号