Attribute errors running tests

After fixing the formatting errors in db.py, tests will run, but I still get two failing tests due to AttributeErrors

self = None, name = ‘movies’

def __getattr__(self, name):
    if name == '__members__':
        return dir(self._get_current_object())
  return getattr(self._get_current_object(), name)

E AttributeError: ‘NoneType’ object has no attribute ‘movies’

…/…/…/anaconda3/lib/python3.7/site-packages/werkzeug/local.py:347: AttributeError
_______________________________________________________________ test_simple_text_search _______________________________________________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_simple_text_search(client):
  (actual, _) = get_movies({"$text": {"$search": "The Martian"}}, 0, 20)

tests/test_db_connection.py:44:


mflix/db.py:222: in get_movies
total_num_movies = db.movies.count_documents(query)


self = None, name = ‘movies’

def __getattr__(self, name):
    if name == '__members__':
        return dir(self._get_current_object())
  return getattr(self._get_current_object(), name)

E AttributeError: ‘NoneType’ object has no attribute ‘movies’

…/…/…/anaconda3/lib/python3.7/site-packages/werkzeug/local.py:347: AttributeError

Hi Jonathan,

In your case, the value of db variable is None. There is no connection with your database.

Perhaps the origin of the error is in the .ini file, in MFLIX_DB_URI parameter in TEST section

Regards.

Hello Jonathan_56351,

I think galindale is correct here - we can see which line is throwing the error from this part of the stack trace:

mflix/db.py:222: in get_movies
total_num_movies = db.movies.count_documents(query)

This means that the command db.movies.count_documents(query) is failing because db.movies won’t work while db is NoneType.

As stated above, properly filling out the .ini file should fix this error. Let me know if this helps!

Matt