Python - Documentation as Tests!

Опубликовано: 12 Октябрь 2024
на канале: codevev
357
14

#Python #Shorts

One cool thing about Python is how easy it is to write tests. The craziest part is, we can use documentation as tests! All we need to do is put "{three greater than signs here}" (Youtube won't allow bracket signs in the description) and the function call on one line, the expected value on the next line, and voila, we have a test! There are a few ways to run those, refer to https://docs.python.org/3/library/doc... to find what suits you best.
One of the simpler ways is to just import "doctest" and call "doctest.testmod()".
-------------------------------------------------------------------------------------
Links:
Blog: https://evgenyurubkov.com
Twitter:   / evgenyurubkov  
Instagram:   / evgenyurubkov  
Youtube:    / @codevev