Error while running "pytest -m projection"

pytest -m projection
============================= test session starts =============================
platform win32 – Python 3.6.5, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: C:\MongoDB Study\M220P\mflix-python, inifile:
plugins: remotedata-0.2.1, openfiles-0.3.0, flask-0.10.0, doctestplus-0.1.3, arraydiff-0.2
collected 35 items / 33 deselected

tests\test_projection.py FF [100%]

================================== 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)
    print(result)
  assert len(result) == 2

E TypeError: object of type ‘TypeError’ has no len()

tests\test_projection.py:16: TypeError
---------------------------- Captured stdout call -----------------------------
unhashable type: ‘list’
_____________________ 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 ‘TypeError’ has no len()

tests\test_projection.py:23: TypeError
=================== 2 failed, 33 deselected in 1.51 seconds ===================

Hi!,

I think the problem is located in line 82 of your db.py file. Your code is returning an exception in line 79 and tests fail. I suppose your query statement in find function is invalid.

It’s the clue I can give you. I hope it helps you.

Regards.

Thanks for help @galindale… I’ll try to fix it there…

Did it work? For you?

@vishal-das Not yet…
Are you facing similar issue.

Yeah man! I tried all my Python logics to pass this but no use of any

@galindale,

I tried the same query in Mongo Compass, its working fine … giving the desired result
But still checking…

Hi again,

Try to execute your find query inside Mongo shell in your computer.

I copied my find query replacing the countries Python variable with a sample array like [“Japan”] in Mongo shell and I received some documents as a response.

Regards

2 Likes