问题是对于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)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)