I am trying to define a test method. Currently I am not receiving any errors, but the test is not actually running. The test is trying to make sure that only the first word in a string that is in list_first_words is being returned.
import unittest
class TestSong(unittest.TestCase):
def first_words_list(self):
self.assertEqual(Song().firstwords(["hello world"]),["hello"])
if __name__ == "__main__":
unittest.main()
Code that is being tested:
def firstwords(self,large_song_list):
all_first_words = [] # Create an empty list
for track in large_song_list:
first_word = track.trackName.partition(' ')[0]
all_first_words.append(first_word)
return all_first_words
You need to rename the test method to test_first_words_list.
Tests are discovered by unittest only when they start with the word test. See "Organizing Test Code" in the documentation for more details.
As described in the documentation:
A testcase is created by subclassing
unittest.TestCase. The three individual tests are defined with methods whose names start with the letterstest. This naming convention informs the test runner about which methods represent tests.
So, you need to rename the method starts with test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With