Index: modules/simpletest/simpletest.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.module,v
retrieving revision 1.75
diff -u -p -r1.75 simpletest.module
--- modules/simpletest/simpletest.module	29 Sep 2009 15:13:56 -0000	1.75
+++ modules/simpletest/simpletest.module	6 Oct 2009 01:46:09 -0000
@@ -334,29 +334,30 @@ function simpletest_test_get_all() {
     }
     else {
       // Select all clases in files ending with .test.
-      $classes = db_select('registry')
-        ->fields('registry', array('name'))
-        ->condition('type', 'class')
-        ->condition('filename', '%.test', 'LIKE')
-        ->execute();
-
-      $groups = array();
+      $classes = db_query("SELECT name FROM {registry} WHERE type = :type AND filename LIKE :name", array(':type' => 'class', ':name' => '%.test'));
 
       // Check that each class has a getInfo() method and store the information
       // in an array keyed with the group specified in the test information.
+      $groups = array();
       foreach ($classes as $class) {
         $class = $class->name;
+        // Test classes need to implement getInfo() to be valid.
         if (class_exists($class) && method_exists($class, 'getInfo')) {
-          // Valid test class, retrieve test information.
           $info = call_user_func(array($class, 'getInfo'));
 
-          // Initialize test groups.
-          if (!isset($groups[$info['group']])) {
-            $groups[$info['group']] = array();
+          // If this test class requires a non-existing module, skip it.
+          if (!empty($info['dependencies'])) {
+            foreach ($info['dependencies'] as $module) {
+              if (!drupal_get_filename('module', $module)) {
+                continue 2;
+              }
+            }
           }
+
           $groups[$info['group']][$class] = $info;
         }
       }
+
       // Sort the groups and tests within the groups by name.
       uksort($groups, 'strnatcasecmp');
       foreach ($groups as $group => &$tests) {
Index: modules/simpletest/simpletest.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.test,v
retrieving revision 1.33
diff -u -p -r1.33 simpletest.test
--- modules/simpletest/simpletest.test	3 Oct 2009 18:09:32 -0000	1.33
+++ modules/simpletest/simpletest.test	6 Oct 2009 01:48:59 -0000
@@ -382,3 +382,25 @@ class SimpleTestMailCaptureTestCase exte
     $this->assertEqual(count($captured_emails), 2, t('All e-mails with the same id are returned when filtering by id.'), t('E-mail'));
   }
 }
+
+/**
+ * Test required modules for tests.
+ */
+class SimpleTestMissingDependentModuleUnitTest extends DrupalUnitTestCase {
+  public static function getInfo() {
+    return array(
+      'title' => 'Testing dependent module test',
+      'description' => 'This test should not load since it requires a module that is not found.',
+      'group' => 'SimpleTest',
+      'dependencies' => array('simpletest_missing_module'),
+    );
+  }
+
+  /**
+   * Ensure that this test will not be loaded despite its dependency.
+   */
+  function testFail() {
+    $this->fail(t('Running test with missing required module.'));
+  }
+}
+
