Index: scripts/run-tests.sh
===================================================================
RCS file: /cvs/drupal/drupal/scripts/run-tests.sh,v
retrieving revision 1.23
diff -u -r1.23 run-tests.sh
--- scripts/run-tests.sh	1 Feb 2009 16:42:26 -0000	1.23
+++ scripts/run-tests.sh	20 Feb 2009 02:40:56 -0000
@@ -81,10 +81,7 @@
 simpletest_script_reporter_display_results();
 
 // Cleanup our test results.
-db_delete("simpletest")
-  ->condition('test_id', $test_id)
-  ->execute();
-
+simpletest_clean_results_table($test_id);
 
 /**
  * Print help text.
Index: modules/simpletest/simpletest.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.module,v
retrieving revision 1.36
diff -u -r1.36 simpletest.module
--- modules/simpletest/simpletest.module	13 Feb 2009 00:39:01 -0000	1.36
+++ modules/simpletest/simpletest.module	20 Feb 2009 02:40:56 -0000
@@ -123,10 +123,7 @@
     }
 
     // Clear test results.
-    if (variable_get('simpletest_clear_results', TRUE)) {
-      db_query('DELETE FROM {simpletest} WHERE test_id = %d', $_SESSION['test_id']);
-      db_query('DELETE FROM {simpletest_test_id} WHERE test_id = %d', $_SESSION['test_id']);
-    }
+    simpletest_clean_results_table($_SESSION['test_id']);
     unset($_SESSION['test_id']);
 
     $all_ok = TRUE;
@@ -515,7 +512,8 @@
 function simpletest_clean_environment() {
   simpletest_clean_database();
   simpletest_clean_temporary_directories();
-  simpletest_clean_results_table();
+  $count = simpletest_clean_results_table();
+  drupal_set_message(t('Removed @count test results.', array('@count' => $count)));
 }
 
 /**
@@ -564,16 +562,34 @@
 }
 
 /**
- * Clear the test results tables.
+ * Clear the test result tables.
+ *
+ * @param $test_id
+ *   Test ID to remove results for, or NULL to remove all results.
+ * @return
+ *   The number of results removed or FALSE.
  */
-function simpletest_clean_results_table() {
+function simpletest_clean_results_table($test_id = NULL) {
   if (variable_get('simpletest_clear_results', TRUE)) {
-    $count = db_result(db_query('SELECT COUNT(test_id) FROM {simpletest_test_id}'));
+    if ($test_id) {
+      $count = db_result(db_query('SELECT COUNT(test_id) FROM {simpletest_test_id} WHERE test_id = :test_id', array(':test_id' => $test_id)));
 
-    // Clear test results.
-    db_query('DELETE FROM {simpletest}');
-    db_query('DELETE FROM {simpletest_test_id}');
+      db_delete("simpletest")
+        ->condition('test_id', $test_id)
+        ->execute();
+      db_delete("simpletest_test_id")
+        ->condition('test_id', $test_id)
+        ->execute();
+    }
+    else {
+      $count = db_result(db_query('SELECT COUNT(test_id) FROM {simpletest_test_id}'));
+
+      // Clear test results.
+      db_delete("simpletest")->execute();
+      db_delete("simpletest_test_id")->execute();
+    }
 
-    drupal_set_message(t('Removed @count test results.', array('@count' => $count)));
+    return $count;
   }
+  return FALSE;
 }
