[issue12928] exec not woking in unittest

2011-09-07 Thread simon

New submission from simon :

works in 2.6, fails in 3.2.2

import unittest
class MyTest(unittest.TestCase):
def test_a(self):
exec(compile("a = 1", '', 'single'))
assert a == 1
if __name__ == '__main__':
unittest.main()

--
components: Library (Lib)
messages: 143672
nosy: simonsteiner
priority: normal
severity: normal
status: open
title: exec not woking in unittest
type: compile error
versions: Python 3.2

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12928] exec not woking in unittest

2011-09-07 Thread simon

simon  added the comment:

seems i need to use

exec(compile("a = 1", '', 'single'), globals())

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12928] exec not woking in unittest

2011-09-07 Thread simon

simon  added the comment:

Can't get this one working:

import unittest
class MyTest(unittest.TestCase):
def test_a(self):
b = 1
exec(compile("a = b + 1", '', 'single'))
assert a == 2
if __name__ == '__main__':
unittest.main()

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12928] exec not woking in unittest

2011-09-08 Thread Ezio Melotti

Ezio Melotti  added the comment:

This doesn't seem related to unittest:

>>> class MyTest:
... def test_a(self):
... b = 1
... exec(compile("a = b + 1", '', 'single'))
... assert a == 2
... 
>>> t = MyTest()
>>> t.test_a()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 5, in test_a
NameError: global name 'a' is not defined

With unittest I get the same error.

--
nosy: +ezio.melotti

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12928] exec not woking in unittest

2011-09-08 Thread Benjamin Peterson

Benjamin Peterson  added the comment:

You're invoking undefined behavior by modifying function locals in exec().

--
nosy: +benjamin.peterson
resolution:  -> invalid
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com