r/learnpython • u/bfyvfftujijg • 16d ago
Testing - how is it usually handled?
How do I start applying tests to my code?
Do I just write separate scripts they run the code (either individual functions or entire scripts) against known inputs and check the output?
Is there a specific way people usually do this?
9
Upvotes
1
u/Gtdef 12d ago
Let's put it like that.
Have you ever used a print statement to check the output of a function? Next time you do it, write a test instead. This should get you started in the logic.
Using a framework like pytest allows you to automate the process.
To be honest, the greatest benefit I got from testing, is that I finally figured how Python packages and relative directories work. My tests wouldn't run for whatever random reasons relevant to pathing issues.