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 Django Basics Test Time Test our Writer model

Why is my Writer class test not passing?

Just wondering why my Writer model class test is not passing on line 13.

from django.test import TestCase
from .models import Writer

class WriterModelTestCase(TestCase):
    '''Tests for the Writer model'''
    def writer_email_test(self):
        writer = Writer.objects.create(
            name="joseph",
            email="jposchel@umabju.com",
            bio="Hello World"
        )
        e_address = self.writer.mailto()
        self.assertIn("jposchel@umabju.com", e_address)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

While your code is technically correct, the task is specifically look for:

Task 2 of 2: Now add a test that creates an instance of the Writer model and, using self.assertIn, make sure the email attribute is in the output of the mailto() method.

For this to pass, all three aspects need to be on the same line:

        self.assertIn(writer.email, writer.mailto())

Thanks! I tried it but I still an error stating, "Your tests didn't pass."

from django.test import TestCase
from .models import Writer

class WriterModelTestCase(TestCase):
    '''Tests for the Writer model'''
    def writer_email_test(self):
        writer = Writer.objects.create(
            name="joseph",
            email="jposchel@umabju.com",
            bio="Hello World"
        )
        self.assertIn(writer.email, writer.mailto())
Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Right! Sorry, the second error was the test name needs to start with test_writer_email not end with writer_email_test.

Yes, the combination of the line above and

def test_writer_email

worked. Thanks so much!