Django Sanity Test Reveals 404 is not 404
<p>I was creating sanity checks in my django tests and came across an error I had accounted for. Unfortunately my test fails when it should be successful. I am testing when a page is not there (a 404 status code). The error message and code are below. When I added quotes I received 404 is not '404'.</p>

<p>Django-1.10.2 &amp; Python 3.4.5</p>

<pre><code>./manage.py test app

Traceback (most recent call last):
  File "/tests/dir/tests.py", line 26, in test_404
    self.assertIs(response.status_code,404)
AssertionError: 404 is not 404

from django.test import TestCase
from django.test import Client

class SanityCheckTests(TestCase):
def test_404(self):
    """
    Http Code 404
    """
    client = Client()

    response = client.get('/test404')
    print(response)
    self.assertIs(response.status_code,404)
</code></pre>

<p>You're on the right track - but <a href="https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertIs" rel="nofollow"><code>assertIs</code></a> ensures you have the same instance of an object. You just want to make sure they are <a href="https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertEqual" rel="nofollow">equal</a>.</p>

<p>Therefore, change your last line to </p>

<pre><code>self.assertEqual(response.status_code, 404)
</code></pre>

python django unit-testing automated-tests http-status-code-404