0

I'm trying to unit test my private class, but import doesn't seem to find my class:

class __MyClass:
     something

from location import __MyClass

class MyClassTest(unittest.TestCase):
     def setUp(self):
          self.test_class = __MyClass(x, y, z)

I've also tried using the entire reference, but it's still unable to find my class.

  • 2
    There is no such thing as a "private" class. Using double-underscores in a class name would be very unusual (note, that never makes something "private" because python doesn't have access modifiers). In any case, what "doesn't work" **exactly**? – juanpa.arrivillaga Jun 14 '22 at 17:01
  • 2
    Note, using an identifier with double leading underscores (and without trailing leading underscores) *anywhere* in a class definition leads to *name mangling*. If you want to avoid that, simply use a single underscore in your class name. – juanpa.arrivillaga Jun 14 '22 at 17:22
  • A reference for further details on name-mangling: https://stackoverflow.com/questions/7456807/python-name-mangling – topsail Jun 14 '22 at 17:48

0 Answers0