Random User Role Assignment in Locust

  • Share this:

Code introduction


This function randomly assigns a user role (admin, editor, viewer) from the Locust library to the passed user object.


Technology Stack : Locust

Code Type : Function

Code Difficulty : Intermediate


                
                    
def random_user_role(user):
    from locust import User
    import random
    roles = ['admin', 'editor', 'viewer']
    return random.choice(roles)                
              
Tags: