Django

Code

Changeset 2253

Show
Ignore:
Timestamp:
02/03/06 17:24:20 (3 years ago)
Author:
adrian
Message:

magic-removal: Improved model unit-test runner to rollback database for each test in case of exception

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/tests/runtests.py

    r2035 r2253  
    4040 
    4141    def report_unexpected_exception(self, out, test, example, exc_info): 
     42        from django.db import connection 
    4243        tb = ''.join(traceback.format_exception(*exc_info)[1:]) 
    4344        log_error(test.name, "API test raised an exception", 
    4445            "Code: %r\nLine: %s\nException: %s" % (example.source.strip(), example.lineno, tb)) 
     46        # Rollback, in case of database errors. Otherwise they'd have 
     47        # side effects on other tests. 
     48        connection.rollback() 
    4549 
    4650normalize_long_ints = lambda s: re.sub(r'(?<![\w])(\d+)L(?![\w])', '\\1', s) 
     
    145149            runner = DjangoDoctestRunner(verbosity_level=verbosity_level, verbose=False) 
    146150            self.output(1, "%s model: Running tests" % model_name) 
    147             try: 
    148                 runner.run(dtest, clear_globs=True, out=sys.stdout.write) 
    149             finally: 
    150                 # Rollback, in case of database errors. Otherwise they'd have 
    151                 # side effects on other tests. 
    152                 connection.rollback() 
     151            runner.run(dtest, clear_globs=True, out=sys.stdout.write) 
    153152 
    154153        if not self.which_tests: