TDD in Python - Leonardo Giordani - @tw_lgiordani - @THEdIGicAT About Me Born in 1977, I started coding in April 1987 on a Sinclair ZX Spectrum. I then moved to MS-DOS PCs and in 1996 I started using Linux and became interested in operating system internals. I love architectures, algorithms, mathematics and cryptography. I currently work as an infrastructure engineer and Python developer. From 2013 I blog some technical thoughts at www.thedigitalcatonline.com In 2018 I published the free book “Clean Architectures in Python” http://bit.ly/getpycabook
TDD in Python - Leonardo Giordani - @tw_lgiordani - @THEdIGicAT We are working too slowly , we solved too few issues last month! Can you increase the productivity of the developers? How many issues did we solve? Not enough! How many issues do you want us to solve? More!
TDD in Python - Leonardo Giordani - @tw_lgiordani - @THEdIGicAT Last month We solved 10 issues, and we need to solve at least 30 of them every month. Can you do something? Well, since every developer works on average one week on an issue, and we have 3 developers we could bla bla... AND PERHAPS BLA BLA... Nice IDEA! Let’s TRY IT! I’ll keep an eye on the issue counter. Thanks.
TDD in Python - Leonardo Giordani - @tw_lgiordani - @THEdIGicAT 1. pick ONE bug/missing feature 2. Write a test THAT FAILS 3. write the minimal code that passes the test 4. REFACTOR the code TDD Workflow
TDD in Python - Leonardo Giordani - @tw_lgiordani - @THEdIGicAT if the test you wrote doesn’t fail ask yourself “Is this test useful?” (which doesn’t mean “the test is useless”, it means “ASK YOURSELF”)
TDD in Python - Leonardo Giordani - @tw_lgiordani - @THEdIGicAT Project Description The goal is to write a class Calc that performs calculations: addition, subtraction, multiplication, and division. Addition and multiplication shall accept multiple arguments. Division shall return a float and division by zero shall return the string "inf". Multiplication by zero must raise a ValueError exception. The class will also provide a function to compute the average of an iterable. This function gets two optional upper and lower thresholds to remove outliers.
TDD in Python - Leonardo Giordani - @tw_lgiordani - @THEdIGicAT Project Description Tests for the average function 1. Average of an iterable (list, tuple) 2. Upper threshold (if > U don’t use it) 3. Lower threshold (if < L don’t use it) 4. Check that thresholds are not included 5. Average of an empty iterable 6. Average of an empty iterable (after thresholds) 7. Thresholds applied to an empty iterable 8. Argument is not iterable
TDD in Python - Leonardo Giordani - @tw_lgiordani - @THEdIGicAT http://www.thedigitalcatonline.com/categories/tdd/ I'm too young to die Useful pytest command line options A simple example of Python OOP development (with TDD) (2 posts) Refactoring with tests in Python: a practical example Hurt me plenty Python Mocks: a gentle introduction (2 posts) Nightmare! A game of tokens: write an interpreter in Python with TDD (4 posts and counting) Clean architectures in Python: a step-by-step example Things I wrote On TDD
TDD in Python - Leonardo Giordani - @tw_lgiordani - @THEdIGicAT http://bit.ly/getpycabook My First Book 9800 readers so far What is a good software architecture? Why should we bother structuring the code and spending time testing it? If you like spending hours debugging your programs or staying late at the office to recover from a buggy deploy in production this book is definitely NOT for you!