<- Test Directory

Checking Status Codes

Test that checks for a 404 response or considers it a failure.


Below is a snippet that allows you to test, for example, that the webserver actually returns a 404 not found. It can be useful to look for specific status codes that you want in replies.

You can apply this to various use cases such as expecting a specific 4xx or 2xx reply from certain content types. If the response below was not a 404 you would see an error reported in your LoadForge report.


import time
from locust import HttpUser, task, between

class QuickstartUser(HttpUser):
    wait_time = between(3, 5)

    def index_page(self):
        with self.client.get("/does_not_exist/", catch_response=True) as response:
            if response.status_code == 404:

This guide is part of the LoadForge Directory, an index of locustfile's for use with LoadForge website and API load tests. We also provide a wizard to generate tests, and onboarding assistance for clients. Contact us should you have any questions.

LoadForge provides load testing and stress tests for websites, APIs and servers. It uses your cloud account to rapidly scale large numbers of simulated users to load test your website, store, API, or application for cheap - just cents per test!

For more help on Tests please see our official documentation. Logged in users can also use our wizard to generate a locustfile, or you can record your browser steps.

Ready to run your test?
Start your first test within minutes.