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

'Response' object has no attribute 'failure' in python3.5.3 #671

Closed
YannickXiong opened this issue Oct 27, 2017 · 3 comments
Closed

'Response' object has no attribute 'failure' in python3.5.3 #671

YannickXiong opened this issue Oct 27, 2017 · 3 comments

Comments

@YannickXiong
Copy link

YannickXiong commented Oct 27, 2017

Description of issue / feature request

I use locust under python3.5.3 to learn to do some performance testing demo, some code as below.
class UserBehavior(TaskSet):

# Execute before any task
def on_start(self):
    pass

@task(1)
def api_query(self):
    with self.client.get("/api/nodes/show.json?name=python") as response:
        if response.content == "":
            response.failure("No data")
        if json.loads(response.content.decode())["id"] != "90":
            response.failure("Got wrong response, id=" + response.content.decode())
        else:
            response.success("Verify Ok!")

when i run locust, i get error message:
cent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/locust/core.py", line 271, in run
self.execute_next_task()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/locust/core.py", line 297, in execute_next_task
self.execute_task(task["callable"], *task["args"], **task["kwargs"])
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/locust/core.py", line 309, in execute_task
task(self, *args, **kwargs)
File "/Users/xiongyang/Desktop/个人/learnning/python3/rfinex_locust.py", line 29, in login
response.failure("Got wrong response, id=" + response.content.decode())
AttributeError: 'Response' object has no attribute 'failure'

Expected behavior

TBD

Actual behavior

TBD

Environment settings (for bug reports)

  • OS:
  • Python version: 3.5.3
  • Locust version:0.8

Steps to reproduce (for bug reports)

TBD - example code appreciated

@YannickXiong
Copy link
Author

I am new to locust, maybe this is a known issue or just I used locust in a wrong way, please some could help me solve this issue? Thx a lot.

@mpaddle
Copy link

mpaddle commented Nov 2, 2017

@YannickXiong you need to catch the response to be able to use it in a with statement, like so:

@task(1)
def api_query(self):
    with self.client.get("/api/nodes/show.json?name=python", 
                          catch_response=True) as response:
        …

@heyman
Copy link
Member

heyman commented Nov 3, 2017

@mpaddle is correct. In order to be able to use the response object as a context manager (with the with statement), you have to set the catch_response keyword argument to True.

@heyman heyman closed this as completed Nov 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants