Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import unittest
  2.  
  3. __private_stuff = 1 # if it would have single underscore, it would not be a problem.
  4.  
  5. class ComplexTestCase(unittest.TestCase):
  6. def test_internal_symbol(self):
  7. self.assertEqual(__private_stuff, 1)
  8.  
  9. unittest.main(__name__)
  10.  
  11. E
  12. ======================================================================
  13. ERROR: test_internal_symbol (__main__.ComplexTestCase)
  14. ----------------------------------------------------------------------
  15. Traceback (most recent call last):
  16. File "C:filesy.py", line 7, in test_internal_symbol
  17. self.assertEqual(__private_stuff, 1)
  18. NameError: global name '_ComplexTestCase__private_stuff' is not defined
  19.  
  20. ----------------------------------------------------------------------
  21.  
  22. import unittest
  23.  
  24. __private_stuff = 1 # if it would have single underscore, it would bot be a problem.
  25.  
  26. class ComplexTestCase(unittest.TestCase):
  27. def test_internal_symbol(self):
  28. private_stuff = globals()['__private_stuff']
  29. self.assertEqual(private_stuff, 1)
  30.  
  31. unittest.main(__name__)
  32.  
  33. import unittest
  34. import other_module
  35.  
  36. __private_stuff = 1 # if it would have single underscore, it would bot be a problem.
  37.  
  38. class ComplexTestCase(unittest.TestCase):
  39. def test_internal_symbol(self):
  40. private_stuff = getattr(other_module, '__private_stuff')
  41. self.assertEqual(private_stuff, 1)
  42.  
  43. unittest.main(__name__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement