I am trying to test a custom error page in a bulb ( 404in this case).
I defined my own 404 page as such:
@app.errorhandler(404)
def page_not_found(e):
print "Custom 404!"
return render_template('404.html'), 404
This works great when deleting an unknown page in the browser (I see Custom 404!in stdout and my user content is visible). However, when I try to start 404 through unittestwith nose, the standard / server page 404 is displayed. I do not receive a log message or user content that I am trying to check.
My test case is defined as follows:
class MyTestCase(TestCase):
def setUp(self):
self.app = create_app()
self.app_context = self.app.app_context()
self.app.config.from_object('config.TestConfiguration')
self.app.debug = False
self.app_context.push()
self.client = self.app.test_client()
def tearDown(self):
self.app_context.pop()
def test_custom_404(self):
path = '/non_existent_endpoint'
response = self.client.get(path)
self.assertEqual(response.status_code, 404)
self.assertIn(path, response.data)
I have app.debugexplicitly installed on Falsein my test application. Is there anything else I should explicitly install?