diff --git a/tests/run-tests.py b/tests/run-tests.py
index 723e41ad59b4c0a2e2afe110d13544c3a6c3a25f_dGVzdHMvcnVuLXRlc3RzLnB5..57179a4bf77aeb358050323a2f3b2a4b2e15e6dd_dGVzdHMvcnVuLXRlc3RzLnB5 100755
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1228,7 +1228,8 @@
             # Meaning of tmpdir has changed since 1.3: we used to create
             # HGTMP inside tmpdir; now HGTMP is tmpdir.  So fail if
             # tmpdir already exists.
-            sys.exit("error: temp dir %r already exists" % tmpdir)
+            print "error: temp dir %r already exists" % tmpdir
+            return 1
 
             # Automatically removing tmpdir sounds convenient, but could
             # really annoy anyone in the habit of using "--tmpdir=/tmp"
@@ -1293,9 +1294,9 @@
     vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
 
     try:
-        sys.exit(runtests(options, tests) or 0)
+        return runtests(options, tests) or 0
     finally:
         time.sleep(.1)
         cleanup(options)
 
 if __name__ == '__main__':
@@ -1297,6 +1298,6 @@
     finally:
         time.sleep(.1)
         cleanup(options)
 
 if __name__ == '__main__':
-    main(sys.argv[1:])
+    sys.exit(main(sys.argv[1:]))