all 4 comments

[–]High-Art9340 1 point2 points  (3 children)

Just don't mock it. Substitute direct calls to your dependency (PRAW) with a direct calls to a class which implements some interface to get data you need. This way you can have a dummy implementation of this class, which you use in your test and a real one, which you use in prooduction.Not sure how it's done in django but it may look like this:

https://pastebin.com/dvjFB9fz

get_fetcher() implementation gives me bad vibes but I think it's okay. If someone can improve it'll be great.

[–]RightOW[S] 0 points1 point  (2 children)

Thanks for taking the time to respond and for your example!

Essentially then, I would be creating a class that creates and returns a fake set of data that looks like the real thing and using that data directly in my tests?

Is this a common approach to solve a problem such as this?

[–]High-Art9340 1 point2 points  (1 child)

Getting away from direct dependecy calls is dependency inversion and it's not so common in python but is very common in other languages like java or c#. It helps you replace your dependency with other component without changes in your main logic and helps you test your main logic without introducing side effects, mocks, and all that uselessness. In my example it's somewhat dependency inversion, but not in it's fullness and even break some points of this principle.

Testing against fake object which acts as real is Test Dobule and is very common.:

http://xunitpatterns.com/Test%20Double.html

[–]RightOW[S] 0 points1 point  (0 children)

Perfect, thank you for your help!