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

前端 未结 9 1300
青春惊慌失措
青春惊慌失措 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条回答
  •  猫巷女王i
    2020-12-28 14:41

    Have you looked into FactoryBoy? https://factoryboy.readthedocs.io/en/latest/orms.html It's a fixtures replacement tool with support for the django orm - factories basically generate orm-like objects (either in memory or in a test database).

    Here's a great article for getting started: https://www.caktusgroup.com/blog/2013/07/17/factory-boy-alternative-django-testing-fixtures/

提交回复
热议问题