-
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
Import issue when the locustfile.py contains importing self-defined class sentence #465
Comments
I have what seems to be a similar issue. My import statement looks like this:
And I get:
|
I think the error is due to my misunderstanding of module concept.
e.g. Below is the folder hierachy put "from pythonClass1 import CLASSA" in root/folder1/ --init--.py 2)in command line level E.g. we are in root/ directory. And you should launch the locust in the following command(still in root/ directory): then it should work. loadTest.py is a file similar like locustfile.py in the official site example. |
Ah ok thanks. I already had an |
I have the same issue, but have not had any luck. I have no problem getting my relative imports to work when running a script off the module itself, but when trying to execute the same module with locust.io I always get the error 'Parent module '' not loaded, cannot perform relative import'. I followed Callie-C-Wang's advice and added all of my imports into my init.py files, as well verified that each folder is a python package (contains an _ init _.py file). My folder structure looks something like the following:
My thought is that it is some sort of effect from how locust.io sets the entry point for the test (test.py in the above example), that is causing it not to acknowledge modules upstream (ie. import.py). However it has no problem importing modules downstream. Any help would be greatly appreciated (currently running Python 3.4). |
@mjone219 I'm betting you've figured this out by now, considering it's been several months, but in case you haven't: I was having the same issue while trying to run the locust file while my terminal was in the same dir as the locust file, but as soon as I stepped back (cd ..) out to the main path and ran the file it was able to find the modules in directories above it. |
@Callie-C-Wang It works fine for me. Thank you. Is there any way I can assign weight to them. For Example Class A can take 80% and Class B as 20%. Like we do with @task(5) |
python -m locust.main -f /path/to/locustfile.py using this command i am not getting any import error. |
@lokeshsaini164: For general help, use Stackoverflow or Slack. For greater chance of success when asking for help there I advice you to put some effort into describing your problem better. |
I think the error is in the dockerfile build: I bypass this problem by adding a new mount in my docker-compose file: where a folder name The correct answer should be to change the dockerfile or the documentation in order that the tests file and their modules should be mount in the working directory:
docker-compose.yml
|
We can setting
2)Set workdir in docker-compose.yml
|
Hi,
I see some import issue when I tried to run load test with the locust command line.
Here is my folder hierachy.
root/
folder1/
pythonClass1.py
folder2/
pythonClass2.py
folder3/
loadTest.py
The pythonClass1.py and pythonClass2.py is normal python class file including Class and some functions.
The loadTest.py file is just like locustfile.py file in the official website
In my load test file loadTest.py, I hope I could reuse the code in pythonClass1 so I try to import pythonClass1 with the following import sentence:
when I run the locust command in the root directory
errors occured
It throws out "Attempted relative import in non-package" and the error like below.
I used the same import sentence for my other simple tests, not load test. it works fine.
When I run my simple tests, I just use "python -m ....." then no such import error occured.
How can I solve this problem when I run "locust -f ...."?
[2016-08-25 15:03:40,180] Unknown/ERROR/stderr: Traceback (most recent call last):
[2016-08-25 15:03:40,180] Unknown/ERROR/stderr: File "C:\Python27\Scripts\locust-script.py", line 9, in
[2016-08-25 15:03:40,180] Unknown/ERROR/stderr:
[2016-08-25 15:03:40,180] Unknown/ERROR/stderr: load_entry_point('locustio==0.7.5', 'console_scripts', 'locust')()
[2016-08-25 15:03:40,180] Unknown/ERROR/stderr: File "C:\Python27\lib\site-packages\locust\main.py", line 349, in main
[2016-08-25 15:03:40,181] Unknown/ERROR/stderr:
[2016-08-25 15:03:40,181] Unknown/ERROR/stderr: docstring, locusts = load_locustfile(locustfile)
[2016-08-25 15:03:40,181] Unknown/ERROR/stderr: File "C:\Python27\lib\site-packages\locust\main.py", line 321, in load_locustfile
[2016-08-25 15:03:40,183] Unknown/ERROR/stderr:
[2016-08-25 15:03:40,183] Unknown/ERROR/stderr: imported = import(os.path.splitext(locustfile)[0])
[2016-08-25 15:03:40,183] Unknown/ERROR/stderr: File "C:\Python27\lib\site-packages\gevent\builtins.py", line 93, in import
[2016-08-25 15:03:40,183] Unknown/ERROR/stderr:
[2016-08-25 15:03:40,183] Unknown/ERROR/stderr: result = _import(_args, *_kwargs)
[2016-08-25 15:03:40,184] Unknown/ERROR/stderr: File "c:\CodeSpace\TestScripts\apitest\src\test\python\testscripts\load\ImportIssue.py", line 7, in
[2016-08-25 15:03:40,184] Unknown/ERROR/stderr:
[2016-08-25 15:03:40,184] Unknown/ERROR/stderr: from ..folder1.pythonClass1 import PythonClass1
[2016-08-25 15:03:40,184] Unknown/ERROR/stderr: File "C:\Python27\lib\site-packages\gevent\builtins.py", line 93, in import
[2016-08-25 15:03:40,184] Unknown/ERROR/stderr:
[2016-08-25 15:03:40,184] Unknown/ERROR/stderr: result = _import(_args, *_kwargs)
[2016-08-25 15:03:40,184] Unknown/ERROR/stderr: ValueError
[2016-08-25 15:03:40,184] Unknown/ERROR/stderr: :
[2016-08-25 15:03:40,184] Unknown/ERROR/stderr: Attempted relative import in non-package
[2016-08-25 15:03:40,184] Unknown/ERROR/stderr:
The text was updated successfully, but these errors were encountered: