Python Locust performance test: locust parameterized (list)---cycle through data, data can be reused

Source: Internet
Author: User
Tags class definition

 from locust Import TaskSet, task, Httplocust 


Class Userbehavior (TaskSet):
def on_start (self): # when modulo When the user starts executing the Taskset class, the On_Start method is called
Self.index = 0

@task
def test_visit (self):
URL = self.locust.share_data[
Self.index] # takes self.locust.share_data< equals Websiteuser class definition Share_data > S Elf.index element
Self.index = (self.index + 1)% len (
self.locust.share_data) # Self.index value less than SE Lf.locust.share_data the length of the loop, generate <0.1.2.3.4, 0.1.2.3.4...>
r = self.client.get (URL) # Taskset class has a client property that returns Self.locust.client
Assert R.status_code = = $


Class Websiteuser (httplocust):
host = '/http Debugtalk.com '
Task_set = userbehavior
Share_data = ['/', '/archives/', '/about/', '/archives/2018/05/', '/a ' Rchives/2018/02/'] # shared data, loop traversal using
Min_wait = $
Max_wait = +

Python locust performance test: locust parameterized (list)---cycle through data, data can be reused

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.