diff -r dfdbb69419da tests/regressiontests/admin_scripts/tests.py
--- a/tests/regressiontests/admin_scripts/tests.py	Thu Jul 31 10:05:13 2008 -0400
+++ b/tests/regressiontests/admin_scripts/tests.py	Thu Jul 31 11:14:54 2008 -0400
@@ -7,6 +7,7 @@
 import unittest
 import shutil
 import sys
+import re
 
 from django import conf, bin, get_version
 from django.conf import settings
@@ -40,21 +41,47 @@
     def remove_settings(self, filename):
         test_dir = os.path.dirname(os.path.dirname(__file__))
         os.remove(os.path.join(test_dir, filename))
-        # Also try to remove the pyc file; if it exists, it could
+        # Also try to remove the compiled file; if it exists, it could
         # mess up later tests that depend upon the .py file not existing
-        try:
-            os.remove(os.path.join(test_dir, filename + 'c'))
-        except OSError:
-            pass
+        def try_remove(name):
+            try:
+                os.remove(os.path.join(test_dir, name))
+            except OSError:
+                pass
+        # Remove *.pyc
+        try_remove(filename + 'c')
+        # Remove *$py.class (for Jython)
+        try_remove(re.sub(r'\.py$', '$py.class', filename))
+
+    def _sys_executable(self):
+        """
+        Returns the command line needed to run a python interpreter, including
+        the options for setting sys.path on Jython, which doesn't recognizes
+        PYTHONPATH.
+        """
+        if sys.platform.startswith('java'):
+            return "%s -J-Dpython.path=%s" % \
+                   (sys.executable, os.environ['PYTHONPATH'])
+        else:
+            return sys.executable
+
+    def _ext_backend_path(self):
+        """
+        Returns the path for the external backend package, or None if no
+        external backend is detected.
+        """
+        first_package_re = re.compile(r'(^[^\.]+)\.')
+        result = first_package_re.findall(settings.DATABASE_ENGINE)
+        if result:
+            backend_pkg = __import__(result[0])
+            backend_dir = os.path.dirname(backend_pkg.__file__)
+            return os.path.dirname(backend_dir)
 
     def run_test(self, script, args, settings_file=None, apps=None):
         test_dir = os.path.dirname(os.path.dirname(__file__))
         project_dir = os.path.dirname(test_dir)
         base_dir = os.path.dirname(project_dir)
-
-        # Build the command line
-        cmd = '%s "%s"' % (sys.executable, script)
-        cmd += ''.join([' %s' % arg for arg in args])
+        ext_backend_base_dir = self._ext_backend_path()
 
         # Remember the old environment
         old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None)
@@ -66,11 +93,14 @@
             os.environ['DJANGO_SETTINGS_MODULE'] = settings_file
         elif 'DJANGO_SETTINGS_MODULE' in os.environ:
             del os.environ['DJANGO_SETTINGS_MODULE']
+        python_path = [test_dir, base_dir]
+        if ext_backend_base_dir:
+            python_path.append(ext_backend_base_dir)
+        os.environ['PYTHONPATH'] = os.pathsep.join(python_path)
 
-        if old_python_path:
-            os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir, old_python_path])
-        else:
-            os.environ['PYTHONPATH'] = os.pathsep.join([test_dir, base_dir])
+        # Build the command line
+        cmd = '%s "%s"' % (self._sys_executable(), script)
+        cmd += ''.join([' %s' % arg for arg in args])
 
         # Move to the test directory and run
         os.chdir(test_dir)
@@ -823,7 +853,7 @@
         out, err = self.run_manage(args)
         self.assertNoOutput(err)
         self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.auth.models'")
-        self.assertOutput(out, os.sep.join(['django','contrib','auth','models.pyc']) + "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]")
+        self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py']))
         self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.contenttypes.models'")
         self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py']))
         self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]")
