_locust_error_handler

appian_locust._locust_error_handler._format_http_error(resp: requests.models.Response, uri: str, username: str) → str
Taken from Response.raise_for_status. Formats the http error message,

additionally adding the username

Parameters
  • resp (Response) – Response to generate an http error message from

  • uri (str) – URI accessed as part of the request

  • username (str) – Username of the calling user

Returns

the http error message to use

Return type

str

appian_locust._locust_error_handler.log_locust_error(e: Exception, error_desc: str = 'No description', location: Optional[str] = None, raise_error: bool = True) → None

This function allows scripts in appian_locust to manually report an error to locust.

Parameters
  • e (Exception) – whichever error occured should be propagated through this variable.

  • error_desc (str) – contains information about the error.

  • location (str) – Codepath or URL path for the error. If non specified, this will become the codepath

  • raise_error (bool) – Whether or not to raise the exception

Returns

None

Example:

if not current_news:
    e = Exception(f"News object: {current} news does not exist.")
    desc = f'Error in get_news function'
    log_locust_error(e, error_desc=desc)
appian_locust._locust_error_handler.raises_locust_error(func: Callable) → Callable

Indicates that the below method should log a locust error

Parameters

func (Callable) – method that could throw an exception

Returns

a wrapped form of that method

Return type

Callable

appian_locust._locust_error_handler.test_response_for_error(resp: locust.clients.ResponseContextManager, uri: str = 'No URI Specified', raise_error: bool = True, username: str = '') → None

Locust relies on errors to be logged to the global_stats attribute for error handling. This function is used to notify Locust that its instances are failing and that it should fail too.

Parameters
  • resp (Response) – a python response object from a client.get() or client.post() call in Locust tests.

  • uri (Str) – URI in the request that caused the above response.

  • username (Str) – identifies the current user when we use multiple different users for locust test)

Returns

None

Example (Returns a HTTP 500 error):