We often need associated processing in automated test cases need to be dynamically class attributes;
The second method is recommended:
Created: setattr ()
Gets: getattr ()
Two types, how to create class attributes loan_id
# First, create # class name attribute name = specific attribute values. Context.loan_id = mysql_data.get ( ' Id ' ) # dynamically create class attributes # Second, creating setattr (translation: attr Dorset) # If the first parameter is an object instance, then this will be for the instance of the object, create an instance attribute # If the first argument for the class, it will create the type attribute # second argument is the name of a string # the third parameter attribute value for the particular setattr (the Context, " loan_id " , mysql_data.get ( ' Id ' )) # setattr (translation: attr Dorset) # first, obtaining loan_id = Context.loan_id # second: acquiring, with loan_id class attribute value of the class among: getattr (attr to Japanese translation) # First parameter is an object instance or class # The second parameter is a string attribute name loan_id = getattr (the Context, " loan_id " )
******* Please respect the original, as to reprint, please indicate the source: Reprinted from: https://www.cnblogs.com/shouhu/ Thank you! ! *******