test error

31 views
Skip to first unread message

Tim Vogt (Tim Vogt)

unread,
Oct 21, 2018, 12:24:52 AM10/21/18
to Django users
I try to make a test with has an error
any suggestions?
tim


    expected_author = f'{post.author}
                                    ^
SyntaxError: EOL while scanning string literal


----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)
Destroying test database for alias 'default'...
MacBook-Pro-15-Officerebel:blogapi timvogt$


from django.test import TestCase
from django.contrib.auth.models import User

from .models import Post

class BlogTests(TestCase):

@classmethod
def setUpTestData(cls):
#Create a user
testuser1 = User.objects.create_user(
username='testuser1', password='abc123')
testuser1.save()

# Create a blog post
test_post = Post.objects.create(
author=testuser1, title='Blog title', body='Body content...')
test_post.save()

def test_blog_content(self):
post = Post.objects.get(id=1)
expected_author = f'{post.author}'
expected_title = f'{post.title}'
expected_body = f'{post.body}'
self.assertEquals(expected_author, 'testuser1')
self.assertEquals(expected_title,'Blog title')
self.assertEquals(expected_body, 'Body content ...')

Tommaso Bellini

unread,
Oct 21, 2018, 8:19:51 AM10/21/18
to django...@googlegroups.com
What does mean 'f' ? It is not imported or instanced..what is it?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/FCBEF0A0-EDB1-4842-BB4E-42249F3F48EB%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Joel

unread,
Oct 21, 2018, 8:26:05 AM10/21/18
to django...@googlegroups.com

Joel

unread,
Oct 21, 2018, 8:29:40 AM10/21/18
to django...@googlegroups.com
What is your version of python? f strings were introduced in 3.6

--

Motaz Hejaze

unread,
Oct 21, 2018, 8:35:47 AM10/21/18
to django...@googlegroups.com

Joel Mathew

unread,
Oct 22, 2018, 11:17:40 AM10/22/18
to django...@googlegroups.com
Why did you say that? I'm using django 2.2 and f strings are indeed supported.

Sincerely yours,

Joel G Mathew
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHV4E-d4qHggazeGzrZJWdf1_Z766SoiJhqXDwizP5Vuox0nVQ%40mail.gmail.com.

Andréas Kühne

unread,
Oct 22, 2018, 1:29:32 PM10/22/18
to django...@googlegroups.com
Hi Joel, 

The fact that you are using Django 2.2 has nothing to do with if f strings are supported. f-strings are a part of the python language. You need to have at least version 3.6 installed to be able to use f-strings. Check your python version by writing : python --version in a command shell. If it's less than 3.6 f strings don't work.

Also regarding how you are writing your tests, you don't need to use an f-string there at all - you can just test:
self.assertEqual(post.author, 'testuser1')

and so on.

Regards,

Andréas


Reply all
Reply to author
Forward
0 new messages