Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test python code on command line

While writing and testing a python method, I am currently using the following approach:

import foo as f
bar = f.bar()

bar.runMyMethodAndSeeIfItWorks()

If I change something in my method, and I need to retest it, I have to execute the following:

f = reload(foo)
bar = f.bar()

bar.runMyMethodAndSeeIfItWorks()

I was wondering if there is a simpler approach to this

like image 779
Karan Avatar asked Aug 31 '26 15:08

Karan


1 Answers

Write a real unit test, and run it from the command line. I find this is one of the most compelling reasons for adopting unit testing: you're going to need to try out your methods as you write them anyway, you might as well do it in a form that will be runnable for evermore after that.

like image 154
Ned Batchelder Avatar answered Sep 03 '26 06:09

Ned Batchelder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!