pytest (py.test) very slow startup in cygwin

后端 未结 1 1688
醉梦人生
醉梦人生 2021-01-07 03:22

In cygwin, py.test starts up very slow. It does not look like a collection issue because of two reasons: The same test starts up quickly in linux. And sometimes, if rerun th

相关标签:
1条回答
  • 2021-01-07 03:44

    The problem is that pytest searches for //pytest.ini, //tox.ini, //setup.cfg, and //setup.py. Each of them caused either genericpath.exists() or genericpath.isfile() to consume about 2.5 seconds.

    On fix is to add the lines below to genericpath.exists() and genericpath.isfile() to skip those four specific paths.

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

    An alternative fix would be to modify _pytest/config.py so it does not form those double-slash in the paths to search.

    The code used to find out the exact problem is pasted below. Set myshow = True so it will show how time is consumed for every file it is searching for.

    $ 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 讨论(0)
提交回复
热议问题