Failed tests running pytest

Here is what I’m seeing

====================================================================== FAILURES =======================================================================
__________________________________________________________________ test_basic_movies __________________________________________________________________

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

@pytest.mark.connection
def test_basic_movies(client):
  (actual, num_found) = get_movies({}, 0, 20)

tests/test_db_connection.py:31:


filters = {}, page = 0, movies_per_page = 20

def get_movies(filters, page, movies_per_page):
    """
    Returns a cursor to a list of movie documents.

    Based on the page number and the number of movies per page, the result may
    be skipped and limited.

    The `filters` from the API are passed to the `build_query_sort_project`
    method, which constructs a query, sort, and projection, and then that query
    is executed by this method (`get_movies`).

    Returns 2 elements in a tuple: (movies, total_num_movies)
    """
  query, sort, project = build_query_sort_project(filters)

E NameError: name ‘build_query_sort_project’ is not defined

mflix/db.py:214: NameError
_______________________________________________________________ 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:


filters = {’$text’: {’$search’: ‘The Martian’}}, page = 0, movies_per_page = 20

def get_movies(filters, page, movies_per_page):
    """
    Returns a cursor to a list of movie documents.

    Based on the page number and the number of movies per page, the result may
    be skipped and limited.

    The `filters` from the API are passed to the `build_query_sort_project`
    method, which constructs a query, sort, and projection, and then that query
    is executed by this method (`get_movies`).

    Returns 2 elements in a tuple: (movies, total_num_movies)
    """
  query, sort, project = build_query_sort_project(filters)

E NameError: name ‘build_query_sort_project’ is not defined

mflix/db.py:214: NameError
================================================================== warnings summary ===================================================================
/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:61: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:78: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:61: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:78: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:61: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:78: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:61: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
/Users/jbrooks/anaconda3/lib/python3.7/site-packages/pytest_flask/plugin.py:78: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

– Docs: https://docs.pytest.org/en/latest/warnings.html
=========================================== 2 failed, 2 passed, 31 deselected, 12 warnings in 2.08 seconds ============================================
(mflix) Jonathans-MacBook-Pro-4:mflix-python jbrooks$

@Jonathan_56351

Both test failures come from this error.

NameError: name ‘build_query_sort_project’ is not defined

Maybe you can check your db.py to see if you accidentally modify the function name.

1 Like

Thanks. This db.py file is a complete mess. It would be better to provide a Github repo than a download. In any event, fixed files are needed soon.

Hello Jonathan_56351,

Thanks for the note. I’m sorry to hear you’ve had an issue with the db.py file. We have pushed some bug fixes to this file, but please continue to report any issues you encounter.

Good luck with the course!

Matt

I had the same issue … running the tests from pytest would fail indicating deprecated methods being invoked, but the application itself ran perfectly producing a validation code.
I looked up the current version of pytest_flask (containing the allegedly deprecated method call) at PyPI (https://pypi.org/search/?q=pytest_flask), updated the pytest_flask version number in the requirements.txt file to this version number and ran the pip install -r requirements again.
After this, the tests run successfully to completion!

HTH,
Milco

2 Likes

Thanks heaps mnuman. That worked for me.

You are the MVP. Thanks so much!

I upgraded to this version as well which fixed my issues with running pytest:
pytest-flask==0.11.0
@mattjavaly maybe you can make this change as well?