DEV Community

Discussion on: PyTest with Django REST Framework: From Zero to Hero

Collapse
marvinkweyu profile image
Marvin

Hi @sherlockcodes ,still trying to understand what is happening in your viewset tests.

I can see methods within it with mocker but I cannot see where it is being set. kindly advice.

Consider a scenario, I have a model viewset, within it, I have overridden the patch to update another model when a certain condition is met.

Collapse
sherlockcodes profile image
Lucas Miguel Author • Edited

I don't think I understand exactly what you are asking. What is is that you can't see where it's being set?

What I am mocking, with the

mocker.patch.object(
            CurrencyViewSet, 'get_queryset', return_value=qs
        )
Enter fullscreen mode Exit fullscreen mode

is the viewset's get_queryset method, so to block access to the database.

In your described scenario. What is it that you want to mock? If it is a method from the viewset, just replace the "get_queryset" part with the name of whatever method you are trying to mock.

Collapse
marvinkweyu profile image
Marvin • Edited

I can see 'mocker' passed as a param, but no import nor config for pytest.

Thread Thread
sherlockcodes profile image
Lucas Miguel Author

Because it's passed as a fixture to the test function. You don't need no imports. It's PyTest's ABC. If you make a basic pytest tutorial or go through this article there's no way you don't encounter fixtures. I encourage you to do a basic pytest tutorial and then go through this article. You should not have any doubts like this left. Hope I was helpful

Thread Thread
marvinkweyu profile image
Marvin

100%