question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve catch_response feature (was previous: Remove catch_response feature from HttpBrowser)

See original GitHub issue

To me - even though I was in favor of it when we implemented it - the catch_response feature is slightly odd, and I’m not sure it should be a feature in Locust. A web app should not return 200 OK if the request in fact failed. I also think it would be a mistake to keep locust features that are focused toward detecting errors in the app that should have been spotted by the app’s own unit/integration tests. Simply because it’s better to focus on one thing (in our case load testing and user simulation) and kick ass at that 😃.

If someone is wandering I’m talking about the following syntax:

from locust import ResponseError

with self.client.get("/inbox", catch_response=True) as response:
    if response.data == "fail":
        raise ResponseError("Request failed")

Part of the reason I’m bringing this up is that I’m currently working on a branch where I’m replacing Locust’s built in HttpBrowser with python requests lib (http://python-requests.org). I have now fully replaced the old client with requests, except for the catch_response feature, and not having to port that feature would save time and code lines 😃.

Does anyone use the catch_response feature extensively? Would anyone miss it 😃?

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
heymancommented, Oct 24, 2012

Actually this got me thinking if maybe we could use the above solution to also solve the allow_http_error use cases.

If the API looked something like this:

# normal request
client.get("/page")

# equivalent of the above
with client.get("/page", catch_response=True): pass

# the "catch_response" use case
# this one will be reported as failure if the content is empty or if the response code is anything else than 2XX
with client.get("/page", catch_response=True) as catched:
    if catched.response.content = "":
        catched.failure("Empty content")

# the allow_http_error use case
# this one will only be reported as success if the response code was 404
with client.get("/page404", catch_response=True) as catched:
    if catched.response.status_code = 404:
        catched.success()
    elif catched.response.status_code = 200:
        catched.failure("Expected 404")

# and if someone want to mark a request as successful no matter what
# i.e equivalent to client.get("/page", allow_http_error=True)
with client.get("/page") as catched:
    catched.success()

But then again maybe it’s weird to wrap the real response object in some other CatchedResponse object, but I do like the fact that it would also solve the use cases where one would want to use the allow_http_error argument.

What do you think?

0reactions
heymancommented, Oct 30, 2012

Fixed by #40

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found