py.test import error "- 'config' not found."

Viewed 18471

While trying to add py.test functionality to a Flask API I ran into the following error message when calling py.test on my source directory

E               ImportStringError: import_string() failed for 'config'. Possible reasons are:
E               
E               - missing __init__.py in a package;
E               - package or module path not included in sys.path;
E               - duplicated package or module name taking precedence in sys.path;
E               - missing module, class, function or variable;
E               
E               Debugged import:
E               
E               - 'config' not found.
E               
E               Original exception:
E               
E               ImportError: No module named config

The issue seems to stem after I have instantiated my Flask app and try to import the config from config.py (line 5).

from flask import Flask

# Setup app
app = Flask(__name__)
app.config.from_object('config')

# Import views
from views import *

if __name__ == '__main__':
    app.run()

Everything seems to work accordingly if I manually set the config variables instead of importing them. Has anyone encountered anything like this? I wasn't able to find anything helpful in the documentation.

6 Answers

Just in case it help someone else, removing the empty __init__.py next to app.py and config.py has resolved my issue.

I was able to continue the usage of: app.config.from_object('config')

Related