Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Testing Be Assertive assertTrue and assertFalse

Jack Cummins
Jack Cummins
17,417 Points

Please help me. Why is my code not working.

I like it when you give code, but then explain the code that you give me.\

The task is: ' We haven't used assertTrue yet but I'm sure you can handle this. assertTrue checks that a value is truthy. Complete the first test using assertTrue. Provide your own good palindrome or use "tacocat". '

Thanks! Jack

tests.py
import unittest

from string_fun import is_palindrome


class PalindromeTestCase(unittest.TestCase):
    def test_good_palindrome(self):
        palin1 = self.is_palindrome()
        palin2 = self.is_palindrome()
        self.assertTrue(palin1 = palin2 )
        pass

    def test_bad_palindrome(self):
        pass
string_fun.py
def is_palindrome(yarn):
    """Return whether or not a string is a palindrome.

    A palindrome is a word/phrase that's the same in
    both directions.
    """
    return yarn == yarn[::-1]

2 Answers

Cooper Runstein
Cooper Runstein
11,850 Points

I think you're misunderstanding the intended use of "is_palindrome" which is a function that tests if a word spelled backwards is still that word. You've set up two functions and checked if they are equivalent, but haven't actually tested whether they work or not.

def test_good_palindrome(self):
        self.assertTrue(is_palindrome("tacocat" )) #test should pass

tl;dr (I only skimmed through your code)

It appears that you used the assignment operator = in place of the equality test operator == on line 10. Also, you don't need the pass keyword if the function is not empty. (The pass keyword doesn't cause an error, but it is strange to use it for non-empty functions.)