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

Prohibits the locustfile from being named 'locust.py' #546

Merged
merged 1 commit into from
Feb 20, 2017

Conversation

cgoldberg
Copy link
Member

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 internal locust 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.

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.")
Copy link
Member

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?

Copy link
Member Author

@cgoldberg cgoldberg Feb 20, 2017

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?

Copy link
Member

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.

Copy link
Member

@justiniso justiniso left a 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.

@cgoldberg cgoldberg merged commit 0bcd0c0 into locustio:master Feb 20, 2017
@cgoldberg cgoldberg deleted the invalid-locustfile-name branch February 20, 2017 16:33
@justiniso justiniso added this to the 0.8.0 milestone Feb 20, 2017
@justiniso justiniso added the bug label Feb 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test file can not be named locust.py (or any other name that is the same as an existing python package)
2 participants