pyeve / eve-sqlalchemy

SQLAlchemy data layer for Eve-powered RESTful APIs
http://eve-sqlalchemy.readthedocs.io
Other
234 stars 70 forks source link

ConfigException ('DOMAIN dictionary missing or wrong.') when running tests #123

Closed bomb-on closed 7 years ago

bomb-on commented 7 years ago

This is probably related to #15, but in my case I have problem ONLY when running tests with py.test.

I prepared a simple EVE (v0.5) app which you can clone here.

With the initial commit I am able to run the app with no problems, however running tests ends up with mentioned exception... Full stack trace looks like this:

[15:15] oxxo@null:~/Sites/evetest <evetest> () $ pytest
============================================================================================================================= test session starts ==============================================================================================================================
platform darwin -- Python 3.5.1, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /Users/oxxo/Sites/evetest, inifile:
/Users/oxxo/.virtualenvs/evetest/lib/python3.5/site-packages/eve/io/mongo/mongo.py:18: ExtDeprecationWarning: Importing flask.ext.pymongo is deprecated, use flask_pymongo instead.
  from flask.ext.pymongo import PyMongo
/Users/oxxo/.virtualenvs/evetest/lib/python3.5/site-packages/eve_sqlalchemy/__init__.py:12: ExtDeprecationWarning: Importing flask.ext.sqlalchemy is deprecated, use flask_sqlalchemy instead.
  import flask.ext.sqlalchemy as flask_sqlalchemy
collected 0 items / 1 errors

==================================================================================================================================== ERRORS ====================================================================================================================================
______________________________________________________________________________________________________________________________ ERROR collecting  _______________________________________________________________________________________________________________________________
../../.virtualenvs/evetest/lib/python3.5/site-packages/_pytest/config.py:325: in _getconftestmodules
    return self._path2confmods[path]
E   KeyError: local('/Users/oxxo/Sites/evetest/evetest/tests')

During handling of the above exception, another exception occurred:
../../.virtualenvs/evetest/lib/python3.5/site-packages/_pytest/config.py:356: in _importconftest
    return self._conftestpath2mod[conftestpath]
E   KeyError: local('/Users/oxxo/Sites/evetest/evetest/tests/conftest.py')

During handling of the above exception, another exception occurred:
../../.virtualenvs/evetest/lib/python3.5/site-packages/eve/flaskapp.py:230: in validate_domain_struct
    domain = self.config['DOMAIN']
E   KeyError: 'DOMAIN'

During handling of the above exception, another exception occurred:
../../.virtualenvs/evetest/lib/python3.5/site-packages/_pytest/config.py:362: in _importconftest
    mod = conftestpath.pyimport()
../../.virtualenvs/evetest/lib/python3.5/site-packages/py/_path/local.py:662: in pyimport
    __import__(modname)
<frozen importlib._bootstrap>:969: in _find_and_load
    ???
<frozen importlib._bootstrap>:958: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:664: in _load_unlocked
    ???
<frozen importlib._bootstrap>:634: in _load_backward_compatible
    ???
../../.virtualenvs/evetest/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:216: in load_module
    py.builtin.exec_(co, mod.__dict__)
evetest/tests/conftest.py:4: in <module>
    from application import application, db
application.py:6: in <module>
    application = Eve(data=SQL)
../../.virtualenvs/evetest/lib/python3.5/site-packages/eve/flaskapp.py:127: in __init__
    self.validate_domain_struct()
../../.virtualenvs/evetest/lib/python3.5/site-packages/eve/flaskapp.py:232: in validate_domain_struct
    raise ConfigException('DOMAIN dictionary missing or wrong.')
E   eve.exceptions.ConfigException: DOMAIN dictionary missing or wrong.

During handling of the above exception, another exception occurred:
../../.virtualenvs/evetest/lib/python3.5/site-packages/py/_path/common.py:366: in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
../../.virtualenvs/evetest/lib/python3.5/site-packages/py/_path/common.py:415: in gen
    for p in self.gen(subdir):
../../.virtualenvs/evetest/lib/python3.5/site-packages/py/_path/common.py:404: in gen
    dirs = self.optsort([p for p in entries
../../.virtualenvs/evetest/lib/python3.5/site-packages/py/_path/common.py:405: in <listcomp>
    if p.check(dir=1) and (rec is None or rec(p))])
../../.virtualenvs/evetest/lib/python3.5/site-packages/_pytest/main.py:670: in _recurse
    ihook = self.gethookproxy(path)
../../.virtualenvs/evetest/lib/python3.5/site-packages/_pytest/main.py:575: in gethookproxy
    my_conftestmodules = pm._getconftestmodules(fspath)
../../.virtualenvs/evetest/lib/python3.5/site-packages/_pytest/config.py:339: in _getconftestmodules
    mod = self._importconftest(conftestpath)
../../.virtualenvs/evetest/lib/python3.5/site-packages/_pytest/config.py:364: in _importconftest
    raise ConftestImportFailure(conftestpath, sys.exc_info())
E   _pytest.config.ConftestImportFailure: ConfigException('DOMAIN dictionary missing or wrong.',)
E     File "<frozen importlib._bootstrap>", line 969, in _find_and_load
E     File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
E     File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
E     File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
E     File "/Users/oxxo/.virtualenvs/evetest/lib/python3.5/site-packages/_pytest/assertion/rewrite.py", line 216, in load_module
E       py.builtin.exec_(co, mod.__dict__)
E     File "/Users/oxxo/Sites/evetest/evetest/tests/conftest.py", line 4, in <module>
E       from application import application, db
E     File "/Users/oxxo/Sites/evetest/application.py", line 6, in <module>
E       application = Eve(data=SQL)
E     File "/Users/oxxo/.virtualenvs/evetest/lib/python3.5/site-packages/eve/flaskapp.py", line 127, in __init__
E       self.validate_domain_struct()
E     File "/Users/oxxo/.virtualenvs/evetest/lib/python3.5/site-packages/eve/flaskapp.py", line 232, in validate_domain_struct
E       raise ConfigException('DOMAIN dictionary missing or wrong.')
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=========================================================================================================================== 1 error in 0.77 seconds ============================================================================================================================

As mentioned in #15, simple workaround is to create a dictionary with the DOMAIN in it and pass it to the constructor (you can try it out in the second commit in my repo).

@mandarvaze mentioned that he had the same problem, but apparently his DOMAIN definition was wrong. It seems to me that this is not the case in my example, so I wonder if this is a "known issue" or am I doing something wrong here?

wjdecorte commented 7 years ago

I had the same error message on two occasions. The first was that Eve could not find my settings.py file. The second was an error in the code in my settings.py. The file "settings.py" is a config file, but is compiled using exec and compile functions to load the values in the namespace. If there are any issues you will get the generic message for ConfigException. In my case, I was assigning a variable outside of my auth subclass which was not recognized and caused an error resulting in this exception.

Good luck!

bomb-on commented 7 years ago

Thanks for all the info, it was very useful indeed! I was trying to run my tests with the simplest possible configuration in settings.py (e.g. DOMAIN = {'whatever': {}} and still not passing settings to Eve constructor) but it was still failing. After a bit more of testing and inspecting what's the issue in my case, I found the "problem" - Eve's load_config method results with wrong path to settings.py. So, since this is strictly Eve issue, I will report it in Eve's repo (if someone else didn't do it already).

bomb-on commented 7 years ago

I will close this. I submitted a PR to Eve's repository and if Nicola accept it, this will be fixed once Eve-SQLAlchemy will support Eve 0.7... Hopefully very very soon™ ;)