Django

Code

Changeset 446

Show
Ignore:
Timestamp:
08/09/05 18:51:55 (3 years ago)
Author:
adrian
Message:

Improved unit-test framework so that it handles database errors more elegantly

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/runtests.py

    r367 r446  
    112112            runner = DjangoDoctestRunner(verbosity_level=verbosity_level, verbose=False) 
    113113            self.output(1, "%s model: Running tests" % model_name) 
    114             runner.run(dtest, clear_globs=True, out=sys.stdout.write) 
    115              
     114            try: 
     115                runner.run(dtest, clear_globs=True, out=sys.stdout.write) 
     116            finally: 
     117                # Rollback, in case of database errors. Otherwise they'd have 
     118                # side effects on other tests. 
     119                db.rollback() 
     120 
    116121        # Run the non-model tests in the other tests dir 
    117122        self.output(1, "Running other tests") 
     
    138143                    log_error(module, "Exception running tests", ''.join(traceback.format_exception(*sys.exc_info())[1:])) 
    139144                    continue 
    140              
     145 
    141146        # Unless we're using SQLite, remove the test database to clean up after 
    142147        # ourselves. Connect to the previous database (not the test database)