
How to learn how to write great tests in Python? - ajushi
I need help. I want to improve. I feel that I&#x27;m not writing the best unit tests. Can you guys recommend any books or articles where I can learn how especially in Python? I&#x27;m more concerned about strategies about knowing what tests to write and when is the best scenario to write them. I really want to be good at development and this area is what I think I&#x27;m lacking. 
I&#x27;d really appreciate your help. Thank you.
======
andrewmatte
My best advice for you is to write modular functions that can be tested
separately rather than integrated stuff that can't be disentangled.

A unit test should test the functionality of a single chunk of code. What kind
of stuff are you writing?

I write webservers most of the time. So what I do is, at the top level of the
request, immediately pull data off of the request so that I can access to the
data in native python types that are easy to mock for testing. Each layer of
my webserver does only one thing which could be gluing the auth+services
together, but is still easy to mock.

------
_ology
You might have a look at the O'Reilly book from August 2, 2017: "Test-Driven
Development with Python: Obey the Testing Goat: Using Django, Selenium, and
JavaScript" 2nd Edition

