Mocking a Django Queryset in order to test a function that takes a queryset

前端 未结 9 1279
青春惊慌失措
青春惊慌失措 2020-12-28 13:55

I have a utility function in my Django project, it takes a queryset, gets some data from it and returns a result. I\'d like to write some tests for this function. Is there a

9条回答
  •  天涯浪人
    2020-12-28 14:39

    Try out the django_mock_queries library that lets you mock out the database access, and still use some of the Django query set features like filtering.

    Full disclosure: I contributed some features to the project.

提交回复
热议问题