0

I have many test cases written by pytest. I am now going to use locust to write some concurrency-related test cases. I found that locust needs to execute a command line first, and then enter some parameters on the user interface to execute these use cases. Can I execute locust directly through pytest code? If an error is reported during execution, the test case will be directly terminated and marked as failed. I hope I can run all test cases (the test cases I wrote before and the test cases written using locust) using pytest command directly.

ffbh
  • 1

2 Answers2

1

You can use Locust as a library to run it via code instead of command line.

https://docs.locust.io/en/stable/use-as-lib.html

Then for doing any pytest asserts, you could use Locust event hooks.

https://docs.locust.io/en/stable/extending-locust.html

I haven't done this with pytest, but I think I should work.

Solowalker
  • 2,431
  • 8
  • 13
0

First and foremost, welcome to StackOverflow, zhoujiazhi. I believe you will find the answer for your question on this already answered question.

Marco.S
  • 383
  • 2
  • 10
  • Thanks for your reply, but this answer does not seem to be what I want. I want the multi-threading function of locust and add it to my pytest as a multi-threading module. Can you briefly describe how to execute locust directly in pytest? – ffbh Feb 19 '21 at 13:44
  • Ok, this is a bit different than what I understood from your original question. Are you maybe referring to [across multiple machines](https://docs.locust.io/en/stable/running-locust-distributed.html)? – Marco.S Feb 19 '21 at 17:30