I have got the following errors when run nosetests
File “/Users/nbnuser/Development/python_tutorial/hardway/projects/gothonweb/tests/app_tests.py”, line 4, in
app.config[‘TESTING’] = True
AttributeError: module ‘app’ has no attribute ‘config’
My app.py:
from flask import Flask
from flask import render_template
from flask import request
app = Flask(__name__)
@app.route('/hello', methods=['POST', 'GET'])
def index():
greeting = 'Hello, World'
if request.method == "POST":
name = request.form['name']
greet = request.form['greet']
greeting = f"{greet} {name}"
return render_template("index.html", greeting=greeting)
else:
return render_template("hello_form.html")
if __name__ == "__main__":
app.run()
This probably has to do with the fact that in your app_test.py you are not calling the correct location of your app.py file on the import statement to import the flask object app.
My app.py file is in the directory under the gothonweb folder "C:\Users\NserName\Documents\projects\gothonweb\gothonweb’. In this type of situation you would edit your app_test.py to look like this.
from nose.tools import *
from gothonweb.app import app
The trick here is telling in the from section where your app.py file is.
Yes I know it should have been projects\ex51\gothonweb but I had to mess around to figure out this issue because in the video example it doesn’t look like Zed covers this or gives us a good over view of how his project folder is structured. I hope this helps you on your coding journey
@Swervin has it:
If you have created your app.py file within 'gothonweb (as it implies in the book but does not specify), then the code within tests/app_tests.py will be wrong.