diff tests/test.py @ 15:cf920f85fb98

more stubbing
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 24 Nov 2011 12:58:32 -0800
parents c3c65fb15ab3
children d3e3a506dd29
line wrap: on
line diff
--- a/tests/test.py	Wed Nov 23 14:29:17 2011 -0800
+++ b/tests/test.py	Thu Nov 24 12:58:32 2011 -0800
@@ -6,10 +6,11 @@
 
 import doctest
 import os
+import shutil
 import sys
+import tempfile
 from optparse import OptionParser
 
-
 def run_tests(raise_on_error=False, report_first=False):
 
     # add results here
@@ -28,12 +29,21 @@
 
     # run the tests
     for test in tests:
+
+        # make a temporary directory for example files
+        tempdir = tempfile.mktemp()
+        shutil.copytree(os.path.join(directory, 'example'), tempdir)
+        doctest_args['extraglobs']['directory'] = tempdir
+        
         try:
             results[test] = doctest.testfile(test, **doctest_args)
         except doctest.DocTestFailure, failure:
             raise
         except doctest.UnexpectedException, failure:
             raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2]
+        finally:
+            # cleanup
+            shutil.rmtree(tempdir)
 
     return results