Le Kim Trang Le Kim Trang - 1 year ago 126
Python Question

How to write Locust result of test api to file

I invoke the test through API,

locust -f locustfile.py --host=http://localhost --no-web --hatch-rate=20 --clients=10000

and got a result

Name # reqs # fails Avg Min Max | Median req/s
POST 8000/queries.json 137 0(0.00%) 5 2 23 | 5 11.00

Total 708 0(0.00%)

I would like to write this result to a file. Can anyone help me with this?

Below is the code in python

def test_topview(self):
post_data_topview = """{ "category": "321", "num": 20, "genderCat" : ["23"] }"""
with self.client.request(method="POST", url="", headers= {"Content-Type" : "application/json"}, data = post_data_topview, catch_response = True ) as response:
if not matched(response.content) :
response.failure("No content")

Thank you very much.

Answer Source

Another option until the statsfile option is live would be to redirect stderr to an output file, which apparently is where the stats are logged to:

 locust -f locustfile.py --host=http://example.com --no-web --clients=20  --hatch-rate=20 --num-request=1000  --only-summary  > locust.log   2>&1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download