Commits

holger krekel committed 82b8417

fix lib-python conftest by removing the unsupported py.test.collect.Directory
and replacing it with shorter and simpler logic

  • Participants
  • Parent commits 0a60a21
  • Branches pytest2

Comments (0)

Files changed (1)

File lib-python/conftest.py

     group.addoption('--filter', action="store", type="string", default=None,
                     dest="unittest_filter",  help="Similar to -k, XXX")
 
-option = py.test.config.option 
-
-def gettimeout(): 
+def gettimeout(timeout): 
     from test import pystone
-    timeout = option.timeout.lower()
     if timeout.endswith('mp'): 
         megapystone = float(timeout[:-2])
         t, stone = pystone.Proc0(10000)
     assert not missing, "non-listed tests:\n%s" % ('\n'.join(missing),)
 check_testmap_complete()
 
-class RegrDirectory(py.test.collect.Directory): 
-    """ The central hub for gathering CPython's compliance tests
-        Basically we work off the above 'testmap' 
-        which describes for all test modules their specific 
-        type.  XXX If you find errors in the classification 
-        please correct them! 
-    """ 
-    def get(self, name, cache={}): 
-        if not cache: 
-            for x in testmap: 
-                cache[x.basename] = x
-        return cache.get(name, None)
-        
-    def collect(self): 
-        we_are_in_modified = self.fspath == modregrtestdir
-        l = []
-        for x in self.fspath.listdir():
-            name = x.basename
-            regrtest = self.get(name)
-            if regrtest is not None:
-                if bool(we_are_in_modified) ^ regrtest.ismodified():
-                    continue
-                #if option.extracttests:  
-                #    l.append(InterceptedRunModule(name, self, regrtest))
-                #else:
-                l.append(RunFileExternal(name, parent=self, regrtest=regrtest))
-        return l 
+def pytest_configure(config):
+    config._basename2spec = cache = {}
+    for x in testmap: 
+        cache[x.basename] = x
 
-def pytest_collect_directory(parent, path):
-    # use RegrDirectory collector for both modified and unmodified tests
-    if path in (modregrtestdir, regrtestdir):
-        return RegrDirectory(path, parent)
-
-def pytest_ignore_collect(path):
-    # ignore all files - only RegrDirectory generates tests in lib-python
-    if path.check(file=1):
-        return True
+def pytest_collect_file(path, parent, __multicall__):
+    # don't collect files except through this hook
+    # implemented by clearing the list of to-be-called
+    # remaining hook methods
+    __multicall__.methods[:] = []
+    regrtest = parent.config._basename2spec.get(path.basename, None)
+    if regrtest is None:
+        return
+    if path.dirpath() not in (modregrtestdir, regrtestdir):
+        return
+    return RunFileExternal(path.basename, parent=parent, regrtest=regrtest)
 
 class RunFileExternal(py.test.collect.File):
     def __init__(self, name, parent, regrtest): 
 
 #
 # testmethod: 
-# invoking in a seprate process: py.py TESTFILE
+# invoking in a separate process: py.py TESTFILE
 #
 import os
 import time
                                    'run-script', 'regrverbose.py')
         
         regrrun = str(regr_script)
-        
-        TIMEOUT = gettimeout()
+        option = self.config.option
+        TIMEOUT = gettimeout(option.timeout.lower())
         if option.pypy:
             execpath = py.path.local(option.pypy)
             if not execpath.check():