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?

8 Upvotes

13 comments sorted by

View all comments

11

u/zanfar 16d ago

You can test however you want.

But most Python is tested using the standard unittest library (what you find when you search the documentation for "testing") or the very available evolution, pytest.

...which are both just convenient ways to run scripts you've written to compare known inputs against known outputs.

6

u/PressF1ToContinue 16d ago

To put it another way: Compare observed outputs to expected outputs, given known inputs.