-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Prohibits the locustfile from being named 'locust.py' #546
Conversation
if not locustfile: | ||
logger.error("Could not find any locustfile! Ensure file ends in '.py' and see --help for available options.") | ||
sys.exit(1) | ||
|
||
if locustfile == "locust.py": | ||
logger.error("The locustfile must not be named `locust.py`. Please rename the file and try again.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message could be more helpful with: Did you mean locustfile.py?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justiniso thanks!
however, the file can be named something else when you use the -f
option. do you think your message implies it must be named locustfile.py
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I mean if someone is naming their file locust.py
, seems like they don't have many locustfiles and are just looking for whatever "default" name works, in which case locustfile.py
suits that need. But I guess it can be misinterpreted. Let's leave it then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me; doesn't stop someone from calling web.py
, though that's probably not very common. If we wanted to make it perfect, it would walk the package dir and look at all of the package contents, but this is easy to read and maintain.
Fixes #138
This PR prohibits naming your locustfile
locust.py
, which previously caused Locust to exit with a misleading message ("No Locust class found").The new behavior is to exit with a more helpful error message explaining not to name the file
locust.py
.The issue was occuring because the locustfile gets imported as a Python module (with the .py extension removed). So naming it
locust.py
caused a namespace clash with the internallocust
module, which would get re-imported instead of the locustfile.Note: This only fixes the common case where you have named it
locust.py
. There are also other reserved names that can not be used as locustfile names. We might want to add something to the docs to explain this.