Reputation: 303
I am new to unittesting and trying to write tests for my code. In my test file, I have defined a test class and have two small tests for my file. However, when I run the file, only the first test runs.
Furthermore, the code I am importing the tests from, in separate functions than the one I am testing, is generating some plots, and those plots are being generated before the test is ran now.
Is there a way I could only run the tests, without having the file I'm importing the functions to be tested from run?
This is my code for the test class :
import unittest
from Expense import set_day_of_the_week
from Expense import add_two_expenses
class Heart_Rate_Model_Tests(unittest.TestCase):
def test_assign_initial_values(self):
day_returned = set_day_of_the_week('Monday')
self.assertEqual(day_return, 'Monday')
def test_add_two_expense(self):
food_expense = 12
drink_expense = 5
expense_sum = add_two_expense(food_expense, drink_expense)
self.assertEqual(17, expense_sum)
if __name__ == '__main__':
unittest.main()
The output obtained from the tests is :
Ran 1 test in 0.001s
OK
I have made changes to the first test to make it fail, and it does fail, therefore I'm sure it's the only test that is being ran, but changes made to it are seen
Upvotes: 2
Views: 1935
Reputation: 99
For everybody who has the same problem in he future: Check your compiling configurations. There might be just one specific test chosen when you click on 'run'.
Upvotes: 0
Reputation: 303
Writing a new test file has fixed the issue. I'm still not sure what it was, I'm assuming it was a configuration error on my side, leaving this here if somebody in the future has a similar issue
Upvotes: 1