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

Dan Badertscher
Dan Badertscher
5,327 Points

assertTrue Challenge

' 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". '

My code:

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

Can someone point me in the right direction?

5 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Dan;

Let's have a look...

Task 1

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".

prompting_code.py
    def test_good_palindrome(self):
        pass

If you look in the other tab, string_fun.py, you see that we have a function to use, is_palindrome. We are asked to use the assertTrue method. If we take a look at the docs we see that it takes an expression and returns a Boolean value, and several examples of it's implementation.

Our challenge then, is to take the argument passed into test_good_palindrome() and check if is_palindrome() return a True value based on a palindrome of our choice. Mr. Love provided one for us, tacocat.

Without trying to explicitly spell out the challenge answer, try it again and see if those steps point you to a solution.

Happy coding,

Ken

Dan Badertscher
Dan Badertscher
5,327 Points

Thank you Ken! The docs link helped out.

Ken Alger
Ken Alger
Treehouse Teacher

Dan;

I have found that checking the docs is often a great place to start. Python's docs are generally pretty good. Some languages have official docs that are not quite so user friendly.

Happy coding,

Ken

None of that really helps me out. Could you possibly help me out on this. I had what he had for the most part.

CHALLENGE TASK 2: FAILING TO PASS. ANY HELP. import unittest

from string_fun import is_palindrome

class PalindromeTestCase(unittest.TestCase): def test_good_palindrome(self): self.assertTrue(is_palindrome('tacocat'))

class PalindromeTestCase(unittest.TestCase): def test_good_palindrome(self): self.assertTrue(is_palindrome('tacocat'))

DO NOT BOTHER I WORKED IT OUT ALONE: import unittest

from string_fun import is_palindrome

class PalindromeTestCase(unittest.TestCase): def test_good_palindrome(self): self.assertTrue(is_palindrome('tacocat')) def test_bad_palindrome(self): self.assertFalse(is_palindrome()) pass

task 1

class PalindromeTestCase(unittest.TestCase): def test_good_palindrome(self): self.assertTrue(is_palindrome('tacocat'))

Hi Annie: I am facing Challenges with the Second Task:

Any Help.

import unittest

from string_fun import is_palindrome

class PalindromeTestCase(unittest.TestCase): def test_bad_palindrome(self): self.assertFalse(is_palindrome('tacocat'))

Hi Sympathy, You are missing not before tacocat, Please write self.assertFalse(is_palindrome('not tacocat')) I think this will help