def METHOD_NAME(self):
    class X:
        def createY(this):
            class Y:
                z = __class__
                self.assertFalse ('__class__' in locals(), "__class__ can not be available in class function")
                self.assertEqual(z, X, "__class__ has to contain the enclosing class object in a class function")
                def methodY(this):
                    y = __class__
                    self.assertTrue ('__class__' in locals(), "__class__ has to be in locals() in a method, where is used")
                    self.assertEqual(y, Y, "__class__ has to contain the class object Y")
            return Y
        def methodX(this):
            yy = __class__
            self.assertTrue ('__class__' in locals(), "__class__ has to be in locals() in a method, where is used")
            self.assertEqual(yy, X, "__class__ has to contain the class object X")
    X().methodX()
    X().createY()().methodY()