[pypy-svn] pypy pytest2: fix lib-python conftest by removing the unsupported py.test.collect.Directory

hpk42 commits-noreply at bitbucket.org
Fri Jan 21 21:40:33 CET 2011


Author: holger krekel <holger at merlinux.eu>
Branch: pytest2
Changeset: r41186:82b8417f7697
Date: 2011-01-20 18:26 +0100
http://bitbucket.org/pypy/pypy/changeset/82b8417f7697/

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

diff --git a/lib-python/conftest.py b/lib-python/conftest.py
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -39,11 +39,8 @@
     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)
@@ -536,43 +533,22 @@
     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): 
@@ -589,7 +565,7 @@
 
 #
 # testmethod: 
-# invoking in a seprate process: py.py TESTFILE
+# invoking in a separate process: py.py TESTFILE
 #
 import os
 import time
@@ -615,8 +591,8 @@
                                    '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():


More information about the Pypy-commit mailing list