'Python unit testing with unittest module
This is how I wrote the code to start a test with the unittest module but it is returning as 0 tests. Is the return making any problems? (I am able to share the complete code but it is long). Posting the code and the script below:
Script:
class Test1(unittest.TestCase): def get_avg(temps, predict_month): #print("Temp:==>>>",temps,"predict_month:=>>>>",predict_month) temp_arr = [] idx_num = month_dict[predict_month] temp_arr.append(float(temps[idx_num])) for i in range (0, 5, 1): idx_num += 1 idx_num = idx_num % 12 temp_arr.append(float(temps[idx_num])) pass # return np.average(temp_arr, axis=0)
Showing the error with 0 tests:
Ran 0 tests in 0.000s OK
I ran the main unittest at the end with this:
if __name__ == '__main__': unittest.main()
I want to know about my faults and loopholes.
Solution 1:[1]
The test function should start with test
:
class Test1(unittest.TestCase):
...
def test_get_avg(temps, predict_month):
#print("Temp:==>>>",temps,"predict_month:=>>>>",predict_month)
temp_arr = []
idx_num = month_dict[predict_month]
temp_arr.append(float(temps[idx_num]))
for i in range (0, 5, 1):
idx_num += 1
idx_num = idx_num % 12
temp_arr.append(float(temps[idx_num]))
pass
# return np.average(temp_arr, axis=0)
...
if __name__ == '__main__':
unittest.main()
Feel free to check the documentation regarding unittest
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |