Pytest -m projection : Error in executing

I tried many times and getting numerous errors.
I could not make out whether to write query in:
a) The find method in the return statement itself


b) The find method is written in the the body of get_movies_by_country (And whether cursor is to be used or not)

Please Help

The code changes should happen in:

def get_movies_by_country(countries):
    Finds and returns movies by country.
    Returns a list of dictionaries, each dictionary contains a title and an _id.


        return list( --- HERE --- )

    except Exception as e_get_movies_by_country:
        return e_get_movies_by_country

It tried and triedcontinously for days and now exhausted completely. Its very strange that the mflix Web app shows connection okay (screenshot attached), but command =>> ( pytest -m connection) gives error (screenshot attached) .Similary command =>> ( pytest -m projection ) also gives error (screenshot attached) even I have written the function definition properly by giving the query in the return statement of get_movies_by country function:


I have written my query in the place show in the function below :

def get_movies_by_country(countries):
Finds and returns movies by country.
Returns a list of dictionaries, each dictionary contains a title and an _id.

    Ticket: Projection

    Write a query that matches movies with the countries in the "countries"
    list, but only returns the title and _id of each movie.

    Remember that in MongoDB, the $in operator can be used with a list to
    match one or more values of a specific field.
    #cursor = db.movies.find({ "countries" : { "$in" : countries } }, { "title" : 1 , _id:0})
    # TODO: Projection
    # Find movies matching the "countries" list, but only return the title
    # and _id. Do not include a limit in your own implementation, it is
    # included here to avoid sending 46000 documents down the wire.
    #return list(db.movies.find({**MY QUERY HERE**}).limit(1))

except Exception as e:
    return e

Please Help

You are running your pytest from tests folder. Run it from main mflix folder by using path like “tests/”

Tried again and again but failed: (also tried fixing fixing and removing .py as well as just executing pytest -m projection ) but every times an error

2 recommendations.

  1. Remove the “limit(1)” part. That was for the sample, and will make your solution fail if you don’t remove it.
  2. in the .ini file there are two “connection strings”, one for Prod and one for Test. Make them the same. If the Prod one is right, but the Test one isn’t, the application will run, but your test will fail.
1 Like

Thanks for your support.
Recommendation No. 1 applied, still giving some error. I am working on it
Recommendation No. 2 was already applied (therefore this may not be the cause of error

(mflix_venv) C:\mflix-python2>pytest -m \mflix-python2\tests\
ImportError while loading conftest ‘C:\mflix-python2\tests\’.
tests\ in
from mflix.factory import create_app
mflix\ in
from mflix.api.movies import movies_api_v1
mflix\api\ in
from mflix.db import get_movie, get_movies, get_movies_by_country,
E File “C:\mflix-python2\mflix\”, line 91
E except Exception as e:
E ^
E SyntaxError: invalid syntax

Invalid Syntax?
Sounds like there is a “}” or “)” or something similar missing.
I am using Visual Studio Code with pylint to help me see that kind of errors.

Now This Error:

The Command Still gives the error but surprisingly
projection in mflix application suceeded:

And the result code was valid?
Then the test code must be corrupted. Maybe you can try “starting over” and making the “right” changes on a “clean” slate.

Thank You again. Yes the code was valid. I could not figure out where to start for clean slate. I fear starting for ground zero again.

Do not fear. Trying to “fix” whatever the issue is can be more time.
Just unpack the application again in a new directory (using the same conda virtual environment), copy your existing .ini file and copy the code changes you did (that is a couple of lines anyway).
And that is all!

1 Like

Thanks Again for your support and help. I will try to do again . Actually I have done earlier at once. I could not spare time from my daily work.