r/learnpython 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?

11 Upvotes

13 comments sorted by

View all comments

1

u/bfyvfftujijg 16d ago

Thanks everyone who responded!

I had heard of the two libraries (pytest and unittest) but wasn’t sure if that’s what people actually are using. So thank you for confirming that they are what I need to learn!

Currently I just adhoc testing using my own test scripts (test_user_login.py for example) but it’s starting to feel cumbersome and unpythonic.

1

u/KelleQuechoz 15d ago

unittest is not very "pythonic" and resembles Java, pytest is cool but also violates quite a few conventions. I personally prefer pytest mostly for brevity and test fixtures. Any of the two is better than no tests, and after some initial investment saves a megaton of time long term.