TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to learn how to write great tests in Python?

1 pointsby ajushiabout 5 years ago
I need help. I want to improve. I feel that I'm not writing the best unit tests. Can you guys recommend any books or articles where I can learn how especially in Python? I'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'm lacking. I'd really appreciate your help. Thank you.

2 comments

andrewmatteabout 5 years ago
My best advice for you is to write modular functions that can be tested separately rather than integrated stuff that can&#x27;t be disentangled.<p>A unit test should test the functionality of a single chunk of code. What kind of stuff are you writing?<p>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.
_ologyabout 5 years ago
You might have a look at the O&#x27;Reilly book from August 2, 2017: &quot;Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and JavaScript&quot; 2nd Edition