Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unittest
- __private_stuff = 1 # if it would have single underscore, it would not be a problem.
- class ComplexTestCase(unittest.TestCase):
- def test_internal_symbol(self):
- self.assertEqual(__private_stuff, 1)
- unittest.main(__name__)
- E
- ======================================================================
- ERROR: test_internal_symbol (__main__.ComplexTestCase)
- ----------------------------------------------------------------------
- Traceback (most recent call last):
- File "C:filesy.py", line 7, in test_internal_symbol
- self.assertEqual(__private_stuff, 1)
- NameError: global name '_ComplexTestCase__private_stuff' is not defined
- ----------------------------------------------------------------------
- import unittest
- __private_stuff = 1 # if it would have single underscore, it would bot be a problem.
- class ComplexTestCase(unittest.TestCase):
- def test_internal_symbol(self):
- private_stuff = globals()['__private_stuff']
- self.assertEqual(private_stuff, 1)
- unittest.main(__name__)
- import unittest
- import other_module
- __private_stuff = 1 # if it would have single underscore, it would bot be a problem.
- class ComplexTestCase(unittest.TestCase):
- def test_internal_symbol(self):
- private_stuff = getattr(other_module, '__private_stuff')
- self.assertEqual(private_stuff, 1)
- unittest.main(__name__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement