Cannot import name 'User' from 'Locust' library - locust

I'm quite new to Locust, just starter tinkering with it a couple of days ago.
Previously I followed someone else's example which was using:
class WebsiteUser(HttpLocust):
# Do stuff
But after reading more documentation I tried to use the User class and now I'm getting errors when I try to import the said class:
I just copy/pasted the example from the docs to make sure I didn't have any typos:
from locust import User, TaskSet, task, between
class MyTaskSet(TaskSet):
#task
def my_task(self):
print("executing my_task")
class MyUser(User):
tasks = [MyTaskSet]
wait_time = between(5, 15)
Response:
local_1 | [2020-05-07 00:54:07,494] c8343450b35a/ERROR/stderr: File "/src/locustfile.py", line 153, in <module>
local_1 | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr:
local_1 | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr: from locust import User, TaskSet, task, between
local_1 | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr:
local_1 | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr: ImportError
local_1 | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr: :
local_1 | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr: cannot import name 'User'
NOTE: I am running locust inside a docker container. And if I switch back to using:
class WebsiteUser(HttpLocust):
task_set = UserBehaviour # class UserBehaviour(TaskSet):
wait_time = between(5.0, 9.0)
everything works fine.
This is my requirements.txt that I'm using:
locustio
influxdb==5.3.0
And I'm using the lastest version of locust docker image locustio/locust:0.14.6
So everything should be up-to-date.
Do you think this is the issue with the documentation and it should be updated or did I miss something and it's my fault?
I also noticed that there is a Locust class that I can import and it seems to behave the same way as the User class, I didn't see any docs the would mention the Locust class though..., does anyone know anything about it?

The documentation at https://docs.locust.io/en/latest/ refers to locust 1.0 (currently available directly from github and as a pre-release package), where all Locust classes have been renamed User.
The current "stable" package (0.14.6) is documented here: https://docs.locust.io/en/stable/
Hopefully that explains your situation.
See the changelog for more information about changes https://docs.locust.io/en/latest/changelog.html

Related

Airflow duplicated plugin entries in virtualenv

Was setting up Airflow (2.1.4) in a virtual environment followed by an install of a third-party plugin "pip install simple-dag-editor"
Plugin installed successfully, however upon checking the plugin list, there were duplicated entries.
(venv) root#test-server:/opt/airflow$ airflow plugins
name | source | flask_blueprints | appbuilder_views
==================+============================================================+=======================================================+=============================================================
simple_dag_editor | simple-dag-editor==0.1.1: | <flask.blueprints.Blueprint object at 0x7f69e5e427b8> | {'category': 'Admin', 'name': 'Simple DAG editor', 'view':
| EntryPoint(name='simple_dag_editor', value='simple_dag_edi | | <simple_dag_editor.app_builder_view.AppBuilderDagEditorView
| tor.simple_dag_editor:SimpleDagEditor', | | object at 0x7f69e5dd1470>}
| group='airflow.plugins') | |
simple_dag_editor | simple-dag-editor==0.1.1: | <flask.blueprints.Blueprint object at 0x7f69e5e427b8> | {'category': 'Admin', 'name': 'Simple DAG editor', 'view':
| EntryPoint(name='simple_dag_editor', value='simple_dag_edi | | <simple_dag_editor.app_builder_view.AppBuilderDagEditorView
| tor.simple_dag_editor:SimpleDagEditor', | | object at 0x7f69e5dd1470>}
| group='airflow.plugins') | |
Airflow portal also resulted in 2 entries in the "Admin" section
Any idea what is happening? I tested the setup again both on a docker container and standalone on the server. Both instances did not result in the duplicated entries therefore I am suspecting it is related to running Airflow in a Python virtual environment. The server is running on CentOS 7.
I believe you might have plugin installed twice in two different places:
In "plugins" folder as simply a python package
Installed as python package
Aiflow Allows for both types of installations, and I think if you have both - it will install both.
If you change the airflow log level to verbose, you should be able to see two entries:
"Loading plugins from entrypoints"
"Loading plugins from directory: <DIRECTORY>"
They should be followed by attempts to import the plugins.
The solution would be to remove the plugings from the "plugins" directory.
It's also possible that you have two packages that have the same entrypoint - for example if you installed it with different package name before, it could also be discovered twice. Airflow checks all pacakges available and if they have appropriate entrypoint declared, it will load it as plugin. But if you enable DEBUG logging level, you should see details. You can easily set airflow logging level by config option (or environment variable):
https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#logging-level

How can I make setup.py to include a class into packaging

I'm using setup.py to package my project. the structure is like:
foo -
|
|--foo/
| |
| |--first.py
| |--second.py
| |--...
|--README
|--requirements.txt
|--scripts/
| |
| |-script1.sh
| |-script2.py
|--service.py
|--setup.py
If I run the current setup.py, which is in accordance with the suggestions here: What is setup.py?
then in the venv/lib/python3.6/site-packages/foo and venv/lib/python3.6/site-packages/scripts I can see all python classes there. But service.py is absent. My question is how to modify the setup.py to include service.py into packaging such that I can find service.py at venv/lib/python3.6/site-packages/?
Thanks in advance!
For top level modules, such as service.py, to be included in the distributions, setuptools offers the py_modules parameter.
The setuptools documentation does not show it clearly, but it is the same as in (now deprecated) distutils:
https://docs.python.org/3/distutils/setupscript.html#listing-individual-modules
setuptools.setup(
# ...
py_modules=['service'], # no '.py'
)

ImportError: cannot import name 'Template'

import numpy as np
from statistics import mean
x=[1,2,3,4,5]
y=[6,7,8,9,10]
m=((mean(x)*mean(y)-mean(x*y))/(mean(x)**2)-(mean(x**2)))
print(m)
In the above the(or any other code where I run numpy), Firstly I am getting an input request when running the program. Something like this:
PS D:\Codes\Python> python practice.py
Enter no.: 1
Enter: 1
which should not happen as values are initialized. I saw in other forums regarding how the file should not be named after a Python module(which you can see, it isn't). Even after that I'm getting error:
"C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 28, in <module>
from string import Template
ImportError: cannot import name 'Template'
Can someone please tell me what to do about it?
Edit:
This problem is only powershell centric. The problem is faced when I run program through powershell. It works fine in IDLE.
There must be a file named "string.py" in your D:\Codes\Python.
You can rename it to solve this issue.
You should not name the file to the modules in Python Standard Library.

Talend Administration Center linking Job to project

I'm trying to create Project and Task in TAC using MetaServletCaller.bat file.
I'm able to create a project using the bat file, but didn't get how to link or assign jobs to that project.
How to create project with the jobs using MetaServletCaller.bat file?
Talend MetaServletCaller API doesn't provide any command for creating a job from an export file. The only way to do this would be to do it in Talend studio, or programmatically using the commandline importItems command which allows you to import an exported job (while logged in to the project):
| importItems source (dir|.zip) imports items |
| -if (--item-filter) filterExpr item filter expression |
| -im (--implicit) import implicit |
| -o (--overwrite) overwrite existing items |
| -s (--status) import the status |
| -sl (--statslogs) import stats & logs params |
You can find the commandline API reference here.

alembic/env.py target_metadata = metadata "No module name al_test.models"

When I use alembic to control the version of my project's database,part of codes in env.py
like:
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from al_test.models import metadata
target_metadata = metadata
when I run 'alembic revision --autogenerate -m "Added user table"', I get an error :
File "alembic/env.py", line 18, in
from al_test.models import metadata
ImportError: No module named al_test.models
so how to solve the question? thanks!
This might be a bit late, and you may have already figured out the issue, but my guess the problem is that your alembic/ directory is not part of the system path. I.e. you need to do something like:
import sys
sys.path.append(path/to/al_test)
from al_test.models import metadata
Update your env.py like this, to add the current working directory to the sys.path that Python uses when searching for modules:
import os
import sys
sys.path.append(os.getcwd())
from al_test.models import metadata
target_metadata = metadata
....
....