Need help.... pytest -m projection - get_movies_by_country

Hi ,

I believe that I did following code in 82 in db.py.
return list(db.movies.find({“countries”: {"$in": countries}},{ “title”: 1}))
I’m still getting in error.TypeError: object of type ‘ServerSelectionTimeoutError’ has no len()
Here is the project code,
@pytest.mark.projection
def test_basic_country_search_db(client):
countries = [‘Kosovo’]
result = get_movies_by_country(countries)
assert len(result) == 2

I’m not seeing the issue in the code… Just wondering what I’m doing wrong

@pytest.mark.projection
def test_basic_country_search_shape_db(client):
countries = [‘Russia’, ‘Japan’]
result = get_movies_by_country(countries)
assert len(result) == 1237
# we should only be returning the _id and title fields
encountered_keys = {}
for movie in result:
for k in movie:
encountered_keys[k] = encountered_keys.get(k, 0) + 1

assert len(list(encountered_keys.keys())) == 2
assert encountered_keys['_id'] == 1237
assert encountered_keys['title'] == 1237

Hi,

I try to hard coded value with following in db,py. Still have issue. I’m getting the error

db.movies.find({“countries”: {"$in": [‘UK’] }},{ “title”: 1})

C:\Users\madur\M220\mflix-python>pytest -m projection
================================================= test session starts =================================================
platform win32 – Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
rootdir: C:\Users\madur\M220\mflix-python
plugins: arraydiff-0.3, doctestplus-0.3.0, flask-0.15.0, openfiles-0.3.2, remotedata-0.3.1
collected 43 items / 41 deselected / 2 selected

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

E TypeError: object of type ‘ServerSelectionTimeoutError’ 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) == 1237

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

tests\test_projection.py:22: TypeError
================================================== warnings summary ===================================================
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.connection_pooling - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.create_update_comments - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.connection - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.delete_comments - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.error_handling - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.errors - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.faceted_search - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.facets - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.get_comments - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.migration - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.paging - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.projection - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.text_and_subfield_search - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.timeouts - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.user_management - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.user_preferences - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325
c:\users\madur\anaconda3\lib\site-packages_pytest\mark\structures.py:325: PytestUnknownMarkWarning: Unknown pytest.mark.user_report - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
PytestUnknownMarkWarning,

– Docs: https://docs.pytest.org/en/latest/warnings.html
============================== 2 failed, 41 deselected, 17 warnings in 60.64s (0:01:00) ===============================

C:\Users\madur\M220\mflix-python>

Hi @Mani_46848,

Were you able to resolve this issue? Let me know if you are still facing it.

Kanika

This issue is resolved. Thanks for checking!

1 Like