Name Error, Chater 1: Projection

I have been getting a name error, like other folks here. The output of pytest is

=================================== FAILURES ===================================
_________________________ test_basic_country_search_db _________________________

client = <FlaskClient <Flask 'mflix.factory'>>

    @pytest.mark.projection
    def test_basic_country_search_db(client):
        countries = ['Kosovo']
        result = get_movies_by_country(countries)
>       assert len(result) == 2
E       TypeError: object of type 'NameError' has no len()

tests/test_projection.py:15: TypeError
______________________ test_basic_country_search_shape_db ______________________

client = <FlaskClient <Flask 'mflix.factory'>>

    @pytest.mark.projection
    def test_basic_country_search_shape_db(client):
        countries = ['Russia', 'Japan']
        result = get_movies_by_country(countries)
>       assert len(result) == 2421
E       TypeError: object of type 'NameError' has no len()

tests/test_projection.py:22: TypeError

This doesn’t seem to be an error based on the function that I edited in db.py, rather an error in the test itself. I have run the function in Jupyter notebook, and I am getting the values that I want. I am able to call len() on the result with no issues.

If possible, I would like to wrap up at least this problem. I don;t think I will be able to get to the final problem for section 1 of this course today.

Thanks,
Chris

Please disregard the post. I think I found my issue. I was not calling the db correctly. I double-checked the .ini file and made sure that test had the correct URI. I then looked at what I was doing in the Jupyter notebook and realized that I was calling the db in a way that I had not defined in the db.py file. So, with a little digging, I realized that movies was not being called, because I did not prepend with “db,” whereas in the Jupyter notebook, I had defined the path differently. Now let’s see if I can wrap up the next challenge before work!

Best,
Chris

1 Like