title: Flask - Can't import app inside test file
body: <p>I'm trying to write some unit tests for a flask application I made. The project is setup like this:</p>
  <pre><code>apiproject (parent folder containing everything)
   /venv
   run.py
   requirements.txt
   /project
     __init__.py
     /departments
       __init__.py
       routes.py
       models.py
     /users
       __init__.py
       routes.py
       models.py
     /tests
       TestUsers.py
  </code></pre>
  <p>run.py:</p>
  <pre><code>from project import app
  
  
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  <p>my actual app is created under project/<strong>init</strong>.py</p>
  <pre><code>from flask import Flask, jsonify, Response
  from flask_sqlalchemy import SQLAlchemy
  from flask_marshmallow import Marshmallow
  import os
  from dotenv import load_dotenv
  from flask_cors import CORS
  
  load_dotenv(verbose=False)
  
  DB_URL = os.getenv(&quot;DATABASE_URL&quot;)
  
  # initialize the application
  app = Flask(__name__)
  </code></pre>
  <p>and in my TestUsers.py I have this:</p>
  <pre><code>import json
  from project import app
  import unittest
  from dotenv import load_dotenv
  load_env(verbose=False)
  
  class TestUsers(unittest.TestCase):
  
      def setUp(self):
          self.app = app
          self.url_prefix = prefix = os.getenv(&quot;URL_PREFIX&quot;)
          self.client = self.app.test_client()
      
      def test_index(self):
          response = self.client.get(self.url_prefix + '/')
          self.assertEqual(response.status_code, 200)
  
     if __name__ == '__main__':
         unittest.main()
  </code></pre>
  <p>When I run TestUsers.py, I get ModuleNotFoundError: No module named 'project'. I tried doing sys.path.append('../') and ../../ inside of TestUsers.py, but that didn't help.</p>