TDD in Python
with pytest and mock
Leonardo Giordani - @lgiordani - thedigitalcatonline.com
TDD in Python with pytest and mock Leonardo Giordani - @lgiordani - - - PowerPoint PPT Presentation
TDD in Python with pytest and mock Leonardo Giordani - @lgiordani - thedigitalcatonline.com About Me Born in 1977 with Star Wars, bash, Apple ][, BSD, finger, Zork, Galaxy Express 999, Little Pollon, Dire Straits, The Police, Rumours, The
with pytest and mock
Leonardo Giordani - @lgiordani - thedigitalcatonline.com
TDD in Python - Leonardo Giordani - @lgiordani
About Me
Born in 1977 with Star Wars, bash, Apple ][, BSD, finger, Zork, Galaxy Express 999, Little Pollon, Dire Straits, The Police, Rumours, The Silmarillion, Squad Leader. Interested in operating systems and computer languages, photography, fantasy and science fiction, video- and boardgames, guitar playing, climbing, horseback riding, Aikido, fencing, rollerskating, drawing, painting, bookbinding. I programmed in Z80 and x86 Assembly, GW-Basic, Logo, Borland Turbo Pascal, Prolog, C, C++, PHP, Lisp, Ada, Objective-C, bash, Python, Erlang, Clojure, Scala, JavaScript. I love mathematics and cryptography.
tl; dr
TDD in Python - Leonardo Giordani - @lgiordani
AMQP - architectures - C - Clojure - compilers - concurrent programming - C++ - decorators - Django - Erlang - functional programming - generators - Git - metaclasses - metaprogramming - Notebook - OOP - operating systems - Python - Python2 - Python3 - RabbitMQ - Scala - TDD - testing - versioning
thedigitalcatonline.com
@thedigicat
TDD in Python - Leonardo Giordani - @lgiordani
Introduction Part 1 - Write a library in TDD Part 2 - Mocks and complex tests Part 3 - Refactoring and legacy code
AGENDA
TDD in Python - Leonardo Giordani - @lgiordani
What you are going to learn today What you can learn in the next years
TDD in Python - Leonardo Giordani - @lgiordani
TDD in Python - Leonardo Giordani - @lgiordani
TDD in Python - Leonardo Giordani - @lgiordani
We a r e wor k i n g t
y , we sol v e d t
e w i ssu e s l a st mon t h ! C a n y
i n c r e a se t h e p r
u c t i v i t y
t h e d e v e l
e r s? H
ma n y i ssu e s d i d we sol v e ? N
e n
gh ! H
ma n y i ssu e s d
w a n t u s t
v e ? Mor e !
TDD in Python - Leonardo Giordani - @lgiordani
L a st mon t h We sol v e d 1 i ssu e s, a n d we n e e d t
v e a t l e a st 3
t h e m e v e r y mon t h . C a n y
d
t h i n g? We l l , si n c e e v e r y d e v e l
e r wor k s
a v e r a ge
e we e k
a n i ssu e , a n d we h a v e 3 d e v e l
e r s we c
l d b l a b l a . . . A N D P E R H A P S B L A B L A . . . N i c e I D E A ! L e t ’ s T R Y I T ! I ’ l l k e e p a n e y e
t h e i ssu e c
n t e r . T h a n k s.
TDD in Python - Leonardo Giordani - @lgiordani
TDD in Python - Leonardo Giordani - @lgiordani
every line of code has a reason
TDD in Python - Leonardo Giordani - @lgiordani
Past tests are always run
TDD in Python - Leonardo Giordani - @lgiordani
There are examples, at least
TDD in Python - Leonardo Giordani - @lgiordani
Never without tests
TDD in Python - Leonardo Giordani - @lgiordani
pick a bug/missing feature Write a test write code that passes the test
TDD Workflow
TDD in Python - Leonardo Giordani - @lgiordani
if the test you wrote doesn’t fail ask yourself “Is this test useful?”
(which doesn’t mean “the test is useless”, it means “double check it”)
TDD in Python - Leonardo Giordani - @lgiordani
TDD in Python - Leonardo Giordani - @lgiordani
TDD in Python - Leonardo Giordani - @lgiordani
STRUCTURE OF THE repository
master mocks refactoring my-tdd my-mocks my-refactoring
git checkout master git checkout -b my-tdd git checkout -t origin/mocks
TDD in Python - Leonardo Giordani - @lgiordani
pytest
https://docs.pytest.org
Where to go now
unittest.mock
https://docs.python.org/3/library/unittest.mock.html
tox
https://tox.readthedocs.io/
travis.ci
https://travis.ci
TDD in Python - Leonardo Giordani - @lgiordani
AMQP - architectures - C - Clojure - compilers - concurrent programming - C++ - decorators - Django - Erlang - functional programming - generators - Git - metaclasses - metaprogramming - Notebook - OOP - operating systems - Python - Python2 - Python3 - RabbitMQ - Scala - TDD - testing - versioning
thedigitalcatonline.com
@thedigicat