This book is a practical guide to making your Django project's tests faster. It has many tips and tricks that apply to all projects, big and small. And it covers the two most popular test runners: Django's test framework and pytest.
It's based on my experience speeding up various Django projects' test suites, improving Django's own testing framework, and creating pytest plugins.
It contains 13 chapters:
1. Introduction - Opening notes, how to use the book.
2. Toolbox - A tour of the various tools you can use to change how your tests run.
3. Measure! - The importance of profiling, with walkthroughs using two different profilers on a test suite.
4. Easy Wins - 11 things you can do in 5 minutes to speed up your test suite.
5. Upgrades - The importance of upgrades, and some how-to guidance to get them done easily.
6. Parallelize - How to use test suite parallelization to boost your tests.
7. Migrations - Reduce the overhead of building your test database.
8. Database Configuration - Tweak your database's configuration to get more speed.
9. CI Configuration - And tweak your CI configuration to boost test speed too.
10. Test Structure - Notes on the best structure for fast, accurate tests, and ways you can restructure.
11. Test Data - The best strategies for creating data in your tests.
12. Targeted Mocking - A guide to mocking, and the best libraries for mocking out specific things such as HTTP requests and time.
13. Outroduction - Closing notes with extra links.
If you'd like a sample of the content, check out these blog posts which contain extracts:
- How to Unit Test a Django Form
- Disable Instrumentation Packages During Tests
- How to Use Django's Parallel Testing on macOS With Python 3.8+
Who are you?
Hi, I'm Adam Johnson. I'm an author and solo consultant working with Ansible, AWS, Django, and Python.
I've used Django since 2012 and have been a member of the Django project Technical Board since the 2.2 release cycle.
Is this an official Django product?
The Django Software Foundation didn't help me out with this book, and this is in no way "official." It's a product of A.W.S. (Adam's Web Services) Ltd.
You should make a donation to the DSF separately!
A PDF watermarked with your email address, and a resources zip file including images and django projects for all the code examples.
Do you offer any discounts?
I offer 50% discount for those living outside of the Top 50 Countries by GDP per capita*. Please email me with the address on my contact details page to say hi, where you live, and what you’re making with Django, and I’ll send you the discount link.
(*According to the IMF 2019 table of countries’ nominal GDP on this Wikipedia page.)
I don't offer any other discount at current but you can follow my blog to be notified of future seasonal discounts.
Can I get an invoice?
Gumroad will you send you a receipt with a "generate" button to turn it into an invoice, so you can really make your employer pay!
Can I get a refund?
If the book is not what you expected, reply to the download email within 30 days and I'll fully refund you, no questions asked (but feedback welcome).
I can't purchase due to US trade sanctions, can I get a free copy?
I'm afraid I don't have time to issue such free copies. Perhaps you can find a way to purchase with the credit card or paypal account of a friend in another country.
”Adam's wonderful book on writing Django tests... I own and recommend it.”
“Today I ran into some tests that were taking minutes. I decided to that was reason enough to finally buy your book. An hour later, I've dropped the test time from 3 minutes to 10s. Thanks!”
“Just finished reading "Speed Up Your Django Tests" by @AdamChainz. It's a good read, found a few nuggets in there. Shame it wasn't available three years ago, but if you're starting your #Django testing adventure today, don't even think twice, grab it”
“So nearly through @AdamChainz’s book. I have to say it’s very good.
Much more than just tests in there.
Not for a novice, but good for everyone from levelling-up to advanced. Recommended.”
“There are a slew of good tips in there that I'm now planning to bring into my company's test suite. I highly recommend it!”
“I liked this book. People who are new in testing journey or a Django developer working with tests, this is for them. Well organized and you cover a very basic stuff that will help beginners to understand testing well.”
”Whenever you find yourself waiting for that test build to finish running - flip a chapter, and you’ll find something to improve. For those who want to go deeper down the rabbit hole, the book is sprinkled generously with references and links.”
“If you already have a basic understanding of Python, Django, and the tests are already running in your Django project, then this Book is for you....
I also sent an email to Adam to ask some questions and got a quick response, which is incredible!“
“This book contains invaluable insights, and I really like the way you organized it.”
“I just finished reading “Speed Up Your Django Tests" by @adamchainz. It’s awesome and i have learned a lot of things. I highly recommend it.”
”Great book! And not only for testing Django apps, lots of great general Python dev tips along the way.”
“It’s a great book! Super easy to find some great advice.”
”@AdamChainz, your book is excellent. It addresses a complex theme - tests optimization - very easily. Applying some of the concepts, I was able to reduce from 40s to 4s in total time for +400 tests.”
“@AdamChainz Your Speed Up Your Django Test book is tops. Creating test data with mixins is a godsend and is much better than the way I was doing it with a file full of methods. Everyone else, I recommend this book!“
“I bought the book and it contains a lot of things which are new to me, although I use django since several years. Thank you for the book.”
“I've been obsessing about fast tests for years, and still learned loads in @AdamChainz's great book. It's super dense with medium-to-advanced tips. Go pick it up!”
You've purchased this product
See it in your libraryView in Library
We charged your card and sent you a receipt
You'll need an account to access this in our app. Please create a password to continue.
Download from the App Store or text yourself a link to the app
Thank you for purchasing, may your tests run fast!
Good news! Since you already have a Gumroad account, it's also been added to your library.