def handle_test ( self , command , * * options ) : # can't be async for testing config = { "async_mode" : False } for key in ( "service_name" , "secret_token" ) : if options . get ( key ) : config [ key ] = options [ key ] client = DjangoClient ( * * config ) client . error_logger = ColoredLogger ( self . stderr ) client . logger = ColoredLogger ( self . stderr ) self . write ( "Trying to send a test error to APM Server using these settings:\n\n" "SERVICE_NAME:\t%s\n" "SECRET_TOKEN:\t%s\n" "SERVER:\t\t%s\n\n" % ( client . config . service_name , client . config . secret_token , client . config . server_url ) ) try : raise TestException ( "Hi there!" ) except TestException : client . capture_exception ( ) if not client . error_logger . errors : self . write ( "Success! We tracked the error successfully! You should be" " able to see it in a few seconds at the above URL" ) finally : client . close ( )
how to capture failure in behave python
Send a test error to APM Server
def handle_test(self, command, **options):
        """Send a test error to APM Server"""
        # can't be async for testing
        config = {"async_mode": False}
        for key in ("service_name", "secret_token"):
            if options.get(key):
                config[key] = options[key]
        client = DjangoClient(**config)
        client.error_logger = ColoredLogger(self.stderr)
        client.logger = ColoredLogger(self.stderr)
        self.write(
            "Trying to send a test error to APM Server using these settings:\n\n"
            "SERVICE_NAME:\t%s\n"
            "SECRET_TOKEN:\t%s\n"
            "SERVER:\t\t%s\n\n" % (client.config.service_name, client.config.secret_token, client.config.server_url)
        )

        try:
            raise TestException("Hi there!")
        except TestException:
            client.capture_exception()
            if not client.error_logger.errors:
                self.write(
                    "Success! We tracked the error successfully! You should be"
                    " able to see it in a few seconds at the above URL"
                )
        finally:
            client.close()