Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support user abstract load shape base classes #2393

Merged
merged 1 commit into from Sep 11, 2023

Conversation

noirbizarre
Copy link
Contributor

@noirbizarre noirbizarre commented Sep 5, 2023

This PR improves the abstract custom base shape detection by using the same pattern than the base User class: abstract base classes should define the abstractattribute to True.

This change is entirely backward compatible and tested.

This PR fixes the following case:

  • define a reusable LoadTestShape in your common modules (let's say lib.BaseShape)
  • create a locust file, create a child shape (cf. below)
  • run the bench

This will result in:

  • without this change, the imported base class is picked as shape, the child class is ignored.
  • with this change, the imported abstract base is ignored and the child class is selected as shape

lib.py

class BaseShape(LoadTestShape):
	abstract = True

	some_class_attr = None # to be provided by child implementation

	def tick(self):
        # Do something with `self.__class__.some_class_attr`

locusfile

from lib import BaseShape

class MyShape(BaseShape):
    some_class_attr = ["my test data"]

Currently, BaseShape will be chosen as shape_class and MyShape will be silently ignored (unless you specify it on the command line, or you rely on the class picker in which BaseShape will appear and shouldn't).

With this change, BaseShape is seen as abstract and is ignored from shape candidates, won't appear in the class picker and MyShape will be chosen if not explicitly told.

@cyberw cyberw merged commit 225b8d6 into locustio:master Sep 11, 2023
13 checks passed
@cyberw
Copy link
Collaborator

cyberw commented Sep 11, 2023

Nice!

@cyberw cyberw changed the title feat(shape): support user base custom load shape Support user abstract load shape base classes Sep 11, 2023
@noirbizarre noirbizarre deleted the shape/inheritance branch September 11, 2023 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants