title: Endpoint Returning 404 from Pytest
body: <p>I have an API that I am working on building the test_app.py file for, but it already works entirely and has been tested via Postman both locally &amp; hosted externally.</p>
  <p>I can't get even my health endpoint to work, which is keeping me (obviously) from making any more tests and moving forward. It's not failing the test, though, it's kicking back 404 when I print the variable I assign to the endpoint.</p>
  <p>test_app.py:</p>
  <pre><code>import os
  import unittest
  import json
  from flask_sqlalchemy import SQLAlchemy
  from app import create_app
  from models import setup_db, Actor, Movie
  
  class CastingAgencyTestCase(unittest.TestCase):
  
      def setUp(self):
          self.app = create_app()
          self.client = self.app.test_client
          self.database_name = &quot;casting_test&quot;
          self.database_path = &quot;postgres://{}/{}&quot;.format(&quot;localhost:5432&quot;, self.database_name)
          setup_db(self.app, self.database_path)
  
          self.new_actor = {
              &quot;name&quot;: &quot;Robert DOwney Jr.&quot;,
              &quot;age&quot;: 45,
              &quot;gender&quot;: &quot;male&quot;
          }
  
          self.new_movie = {
              &quot;title&quot;: &quot;Iron Man&quot;,
              &quot;release_date&quot;: &quot;02/03/2004&quot;
          }
          with self.app.app_context():
              self.db = SQLAlchemy()
              self.db.init_app(self.app)
              self.db.create_all()
  
      def tearDown(self):
          pass
  
      def test_health(self):
          res = self.client().get('/')
          print(res)
          data = json.loads(res.data)
  
          self.assertEqual(res.status_code, 200)
          self.assertIn('health', data)
          self.assertEqual(data['health'], 'App is running.')
  
  if __name__ == &quot;__main__&quot;:
      unittest.main()
  </code></pre>
  <p>The output of that <code>print(res)</code> is <code>&lt;Response streamed [404 NOT FOUND]&gt;</code>, and then the test fails because there is nothing in res.data, but of course not because the page isn't found.</p>
  <p>app.py (up to where the health endpoint is created):</p>
  <pre><code>import os
  from flask import Flask, request, abort, jsonify, render_template, \
      redirect, url_for, send_from_directory
  from flask_sqlalchemy import SQLAlchemy
  from flask_cors import CORS
  from models import Actor, Movie, setup_db, db_drop_and_create_all, db
  from auth import AuthError, requires_auth
  
  
  def create_app(test_config=None):
      app = Flask(__name__)
      setup_db(app)
      CORS(app, resources={r&quot;/*&quot;: {&quot;origins&quot;: &quot;*&quot;}})
  
      # db_drop_and_create_all()
  
      return app
  
  app = create_app()
  
  if __name__ == '__main__':
      app.run(host='127.0.0.1', port=5000, debug=True)
  
  # -----------
  # @app.routes
  # -----------
  
  
  @app.after_request
  def after_request(response):
      response.headers.add('Access-Control-Allow-Headers',
                           'Content-Type, Authorization')
      response.headers.add('Access-Control-Allow-Methods',
                           'GET, POST, PATCH, DELETE, OPTIONS')
      return response
  
  
  @app.route('/')
  def home():
      return jsonify({
          'success': True,
          'health': 'App is running.'
      }), 200
  </code></pre>
  <p>models.py (to the point where setup_db is created):</p>
  <pre><code>import os
  from flask_sqlalchemy import SQLAlchemy
  from sqlalchemy import Column, String, Integer, ForeignKey, Float, Date, Table
  from flask_migrate import Migrate
  
  # ---------
  # Config.
  # ---------
  
  database_path = os.environ.get('DATABASE_URL')
  if not database_path:
      database_name = &quot;agency&quot;
      database_path = &quot;postgres://{}:{}@{}/{}&quot;.format(
          'postgres', 'root', 'localhost:5000', database_name)
  
  db = SQLAlchemy()
  
  
  def setup_db(app, database_path=database_path):
      app.config[&quot;SQLALCHEMY_DATABASE_URI&quot;] = database_path
      app.config[&quot;SQLALCHEMY_TRACK_MODIFICATIONS&quot;] = False
      db.app = app
      db.init_app(app)
  </code></pre>
  <p>After finding some videos regarding this kind of testing, I can't figure out why the page might kick back 404.</p>