Skip to content

Instantly share code, notes, and snippets.

@snackattas
Created August 17, 2020 17:07
Show Gist options
  • Save snackattas/b38c461e25e79cc92213cf0a82b15823 to your computer and use it in GitHub Desktop.
Save snackattas/b38c461e25e79cc92213cf0a82b15823 to your computer and use it in GitHub Desktop.
Sample locust taskset showing off Setup happening outside locust hooks
class Setup(object):
ACCOUNT_ID = None
USER_SESSION = None
LOCATION_IDS = None
REVIEW_IDS = None
def __init__(self):
self.ACCOUNT_ID = environ.get('ACCOUNT_ID')
self.USER_SESSION = self.create_user_session()
self.LOCATION_IDS = self.get_location_ids_from_db()
self.REVIEW_IDS = self.get_review_ids_from_db()
class Entrypoint(HttpUser):
Setup() # this will only run once
tasks = [MainTask]
class MainTask(TaskSet):
def on_start(self):
self.account_id = Setup.ACCOUNT_ID
self.user_session = Setup.USER_SESSION
self.location_ids = Setup.LOCATION_IDS
self.review_ids = Setup.REVIEW_IDS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment