[pypy-svn] r55015 - pypy/django/tests

hpk at codespeak.net hpk at codespeak.net
Tue May 20 17:20:45 CEST 2008


Author: hpk
Date: Tue May 20 17:20:45 2008
New Revision: 55015

Modified:
   pypy/django/tests/conftest.py
Log:
(anto, hpk with samuele around) 
trying to run invalid model tests with a teardown so that it doesn't break django 



Modified: pypy/django/tests/conftest.py
==============================================================================
--- pypy/django/tests/conftest.py	(original)
+++ pypy/django/tests/conftest.py	Tue May 20 17:20:45 2008
@@ -57,6 +57,8 @@
 
 class DjangoTestModule(py.test.collect.Module):
     def run(self):
+        if self.name.startswith("invalid"):
+            return ["%invalidtestcase%"]
         mod = self._get_mod()
         result = self._tests_from_mod(mod)
         modpath = py.path.local(mod.__file__)
@@ -71,9 +73,7 @@
     def _tests_from_mod(self, mod):
         result = []
         # "invalid" test case 
-        if self.name.startswith("invalid"):
-            return ["%invalidtestcase%"]
-        elif hasattr(mod, 'suite'):
+        if hasattr(mod, 'suite'):
             s = mod.suite()
             namemethods = getmethods2(s) 
             meth = []
@@ -116,6 +116,8 @@
         return mod
 
     def join(self, name):
+        if name == '%invalidtestcase%':
+            return DjangoInvalidModelTestCase(name, self) 
         mod = self._get_mod()
         if name == '%docstring%':
             return DocTestItem(self.fspath.basename + '.%docstring%', mod, mod.__test__['API_TESTS'])
@@ -126,8 +128,6 @@
             return DocTestItem(self.fspath.basename + '.%docstring%', mod, mod.__doc__)
         elif name == 'tests.%docmodulestring%':
             return DocTestItem(self.fspath.basename + '.test.%docstring%', mod, mod.__doc__)
-        elif name == '%invalidtestcase%':
-            return DjangoInvalidModelTestCase(name, self) 
         elif name.startswith('tests'):
             return DjangoUnitTest(name, self) 
         else:
@@ -135,8 +135,14 @@
 
 class DjangoInvalidModelTestCase(py.test.collect.Item):
     def run(self):
+        return 
         testcase = InvalidModelTestCase(self.parent.name)
-        run_testcase_method(testcase) 
+        try:
+            run_testcase_method(testcase) 
+        finally:
+            from django.conf import settings
+            basedir = self.fspath.dirpath().basename 
+            settings.INSTALLED_APPS.remove(basedir + "." + self.parent.name) 
         
 class DjangoUnitTest(py.test.collect.Item):
     def run(self):



More information about the Pypy-commit mailing list