入口点.py
from other_file import UserBehaviour
class ApiUser(HttpUser):
tasks = [UserBehaviour]
def on_start(self):
# log in and return session id and cookie
# example: self.foo = "foo"
其他文件.py
from entry_point import ApiUser
class UserBehaviour(TaskSet):
@task
def do_something(self, session_id, session_cookie)
# use session id and session cookie from user instance running the taskset
# example: print(self.ApiUser.foo)
注意:通过文档,我确实发现“可以通过 TaskSet.user 从 TaskSet 实例中访问 User 实例”,但是我将用户导入任务集文件的所有尝试都导致了"cannot import name 'ApiUser' from 'entry_point'"
错误。如果不是from entry_point import ApiUser
I do from entry_point import *
,那么我会收到name 'ApiUser' is not defined
错误消息。