codestr = '''def f():
"""doc"""
+ debug_enabled = False
+ if __debug__:
+ debug_enabled = True
try:
assert False
except AssertionError:
- return (True, f.__doc__)
+ return (True, f.__doc__, debug_enabled)
else:
- return (False, f.__doc__)
+ return (False, f.__doc__, debug_enabled)
'''
def f(): """doc"""
- values = [(-1, __debug__, f.__doc__),
- (0, True, 'doc'),
- (1, False, 'doc'),
- (2, False, None)]
- for optval, debugval, docstring in values:
+ values = [(-1, __debug__, f.__doc__, __debug__),
+ (0, True, 'doc', True),
+ (1, False, 'doc', False),
+ (2, False, None, False)]
+ for optval, assertval, docstring, debugval in values:
# test both direct compilation and compilation via AST
codeobjs = []
codeobjs.append(compile(codestr, "<test>", "exec", optimize=optval))
ns = {}
exec(code, ns)
rv = ns['f']()
- self.assertEqual(rv, (debugval, docstring))
+ self.assertEqual(rv, (assertval, docstring, debugval))
def test_delattr(self):
sys.spam = 1