#NEWLINE# @ istest #NEWLINE# def checks_if_a_package_exists_before_installing( self ) : #NEWLINE# #INDENT# with self . execute_mock ( ) as execute , self . mock_role_methods ( 'package_exists' , 'is_package_installed' ) as ( package_exists , is_package_installed ) : #NEWLINE# #INDENT# is_package_installed . return_value = False #NEWLINE# package_exists . return_value = True #NEWLINE# result = self . role . ensure_package_installed ( 'python' ) #NEWLINE# self . assertTrue ( result ) #NEWLINE# self . assertTrue ( package_exists . called ) #NEWLINE# execute . assert_called_with ( 'yum install -y python' , stdout = False , sudo = True )