I am working on setting up unit tests in my flask project right now. My test file is below:
import flask_testing
import unittest
from flask import Flask
from flask_testing import TestCase
class MyTest(TestCase):
def setUp(self):
pass # Executed before each test
def tearDown(self):
pass # Executed after each test
def create_app(self):
app = Flask(__name__)
# app.config['TESTING'] = True
return app
def test_greeting(self):
response = self.client.get('/')
print("should return 404 on landing page")
self.assertTemplateUsed('index.html')
self.assertEqual(response.status_code, 200)
if __name__ == '__main__':
unittest.main()
When I run these tests the assertTemplateUsed
does not return a template and the response.status_code
is 404. I imagine this is because self is not actually my application for some reason? When I run the app the root address definitely returns index.html.
Am I setting up create_app
wrong? Any help is appreciated.