Peter Jordanson
Peter Jordanson

Reputation: 91

AssertionError in Unit Test | Response Data suggests otherwise

Hey so I'm running Unit Tests on my 'Logout' function and am receiving an AssertionError where I don't understand why it exists.

Here's the error (response data cut down for readability):

self.assertIn(b'Logged out', response.data)
AssertionError: b'Logged out' not found in b'<!DOCTYPE html>
...
<li>Logged Out </li>
...

I'd expect this not to return an AssertionError, seeing as the text 'Logged out' is found in the response data.

EDIT: Here's my test function if that's of any help

def test_logout(self):
        self.app.get('/register', follow_redirects = True)
        self.register("username", "[email protected]", "password", "password", "preference")
        self.app.get('/login', follow_redirects = True)
        self.login("username", "password")
        response = self.app.get('/logout', follow_redirects = True)
        self.assertIn(b'Logged out', response.data)

Upvotes: 1

Views: 727

Answers (1)

Peter Featherstone
Peter Featherstone

Reputation: 8102

The assertion error suggests that the O in out is capitalised yet you are testing against an uncapitalised o.

Python is case sensitive when making assertions as it should be so update your test to:

self.assertIn(b'Logged Out', response.data)

Upvotes: 2

Related Questions