I am new to Python, so I apologize in advance if this is a lot for something basic.
I have a situation similar to How to set up a Flask application with SQLAlchemy for testing? For me, the big difference is that, unlike most other Flask examples that I see on the Internet, most of the code that I have for my application is in the class. For some reason, this leads to the malfunctioning of my unit testing. Below is the basic setup of my application and tests:
Application:
from Flask import Flask app = Flask(__name__) class MyApplication(): def __init__(self, param1, param2): app.add_url("/path/<methodParam>", "method1", self.method1, methods=["POST"])
Application Tests:
import unittest from apppackage import MyApplication class ApplicationTestCase(unittest.TestCase): def setUp(self): self.tearDown() param1 =
When I run my tests through
nosetests - with-coverage -cover-package apppackage. / test / test _application.py
I get the following error:
param2) .app.test_client () AttributeError: MyApplication instance has no 'app' attribute
I tried moving the application inside the class declaration, but it is of no use, and it is not like every other unit testing tool I have seen. Why can't my unit tests find the "app" attribute?
source share