[Python] Python mock to create a fake object return a dictionary when any of its attributes...

Discussão em 'Python' iniciado por Stack, Janeiro 30, 2025.

  1. Stack

    Stack Membro Participativo

    for example I have a method in Django which reuses the request object:

    def dowork(request):
    # the sessionid is a query param of the callback from payment gateway
    print request.GET.get('sessionid')


    When I write unittest, I need to create a fake request object, which should have GET attribute and should contain a dictionary {'sessionid': 'blah'}

    How do I do that using the mock package?

    Continue reading...

Compartilhe esta Página