Question

I have built a hybrid library in python for robotframework. One of the methods of this API returns a string that I want to assign to a robotframework variable in a test.

${sms_1_2}=   encrypt_sms_return_ciphered     1@ercom.fr      2@ercom.fr      sms1to2

I have verified that the python code of encrypt_sms_return_ciphered did return a string. But the problem is that the robotframework variable is assigned to None.

Here is the method code :

@InstanceIndex.check_short_name
def encrypt_sms__return_ciphered(self, sender, receiver, clearsms):
    self.encrypt_sms(sender, receiver, clearsms)
    ClientIndex.success_if(sender, "isSmsSent", receiver,  clearsms)
    cipheredsms = self.smsSent[receiver, clearsms]
    del self.smsSent[receiver, clearsms]
    return cipheredsms

Here is the code of check_short_name decorator :

@staticmethod
def check_short_name(method):
    def wrapper(self, short_name, *args, **kwargs):
        if short_name != self.short_name:
            try:
                getattr(self.collection.iterate(), method.__name__)(short_name, *args, **kwargs)
            except StopIteration:
                raise Exception("item \"%s\" is not a member of %s, or method \"%s\" is not defined for any member of %s" % (short_name, self.collection.name, method.__name__, self.collection.name))
        else:
            self.collection.rewind()
            return method(self, short_name, *args, **kwargs)
    return wrapper
Was it helpful?

Solution

I found out what the problem was : the return value chain was broken from the start. There was no return before the getattr :

@staticmethod
def check_short_name(method):
    def wrapper(self, short_name, *args, **kwargs):
        if short_name != self.short_name:
            try:
                **return** getattr(self.collection.iterate(), method.__name__)(short_name, *args, **kwargs)
            except StopIteration:
                raise Exception("item \"%s\" is not a member of %s, or method \"%s\" is not defined for any member of %s" % (short_name, self.collection.name, method.__name__, self.collection.name))
        else:
            self.collection.rewind()
            return method(self, short_name, *args, **kwargs)
    return wrapper
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top