I'm practising tdd with Flask and funny enough my first test file can't seem to detect the main flask_app file:
test_basics.py :
from flask_testing import TestCase
from flask_app import app
import unittest
class TestBasics(TestCase):
def test_home_route(self):
with self.client:
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
self.assertTrue(response.data == b'hakuna matata')
if __name__ == '__main__':
unittest.main()
I created setup.py
so the root directory is treated as a project directory:
from distutils.core import setup
from setuptools import find_packages
setup(
version='0.0.1',
description='training',
name='flask'
)
project structure:
├── flask_app.py
├── __pycache__
│ └── flask_app.cpython-38.pyc
├── setup.py
├── tests
│ └── test_basics.py
└── venv
export FLASK_APP=flask_app.py
export FLASK_ENV=development
flask run
What do I need to do so the tests can run against the main flask_app.py file ?
python tests/test_basics.py
returns:
ModuleNotFoundError: No module named 'flask_app'