Best Python code snippet using locust
users.py
Source:users.py
...27 raise HTTPException(status_code=404, detail="User not found")28 return user29async def create_user(user: schema.UserCreate):30 hashed_password = get_password_hash(user.password)31 _id = await get_current_user_count()32 db_user = User(33 id=_id,34 first_name=user.first_name,35 last_name=user.last_name,36 email=user.email,37 is_active=user.is_active,38 is_superuser=user.is_superuser,39 title=user.title,40 company=user.company,41 hashed_password=hashed_password42 )43 await db_user.save()44 return db_user45async def delete_user(user_id: int):...
locustfile.py
Source:locustfile.py
...24 def tick(self):25 if self.step >= len(self.targets_with_times):26 return None27 target = self.targets_with_times[self.step]28 users = self.get_current_user_count()29 if target.users == users:30 if not self.time_active:31 self.reset_time()32 self.time_active = True33 run_time = self.get_run_time()34 if run_time > target.dwell:35 self.step += 136 self.time_active = False...
db.py
Source:db.py
...8 try:9 yield client10 finally:11 client.close()12async def get_current_user_count():13 client = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)14 count = await client.get('user_count')15 await client.incr('user_count')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!