~landscape/zope3/ztk-1.1.3

« back to all changes in this revision

Viewing changes to src/zope/testing/testrunner/tb_format.py

  • Committer: Sidnei da Silva
  • Date: 2009-10-07 18:25:02 UTC
  • mfrom: (9.1.4 newer-zope-testing-redux)
  • Revision ID: sidnei.da.silva@canonical.com-20091007182502-5wo2v3k0537eezco
Merged newer-zope-testing [r=therve,oubiwann] [f=438818].

Update to zope.testing 3.8.3 + the bugfix for Bug #445632.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
 
4
# All Rights Reserved.
 
5
#
 
6
# This software is subject to the provisions of the Zope Public License,
 
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
 
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 
11
# FOR A PARTICULAR PURPOSE.
 
12
#
 
13
##############################################################################
 
14
"""Set up testing environment
 
15
 
 
16
$Id: __init__.py 68482 2006-06-04 14:58:55Z jim $
 
17
"""
 
18
 
 
19
import sys
 
20
import traceback
 
21
import zope.exceptions.exceptionformatter
 
22
import zope.testing.testrunner.feature
 
23
 
 
24
 
 
25
def format_exception(t, v, tb, limit=None):
 
26
    fmt = zope.exceptions.exceptionformatter.TextExceptionFormatter(
 
27
        limit=None, with_filenames=True)
 
28
    return fmt.formatException(t, v, tb)
 
29
 
 
30
 
 
31
def print_exception(t, v, tb, limit=None, file=None):
 
32
    if file is None:
 
33
        file = sys.stdout
 
34
    file.writelines(format_exception(t, v, tb, limit))
 
35
 
 
36
 
 
37
class Traceback(zope.testing.testrunner.feature.Feature):
 
38
 
 
39
    active = True
 
40
 
 
41
    def global_setup(self):
 
42
        self.old_format = traceback.format_exception
 
43
        traceback.format_exception = format_exception
 
44
 
 
45
        self.old_print = traceback.print_exception
 
46
        traceback.print_exception = print_exception
 
47
 
 
48
    def global_teardown(self):
 
49
        traceback.format_exception = self.old_format
 
50
        traceback.print_exception = self.old_print