0

This is my first time trying to write a test and I'm guessing I made some obvious screw up with writing the test itself.

Here is my test:

from django.test import TestCase

from accounts.forms import UserReview

class MyTests(TestCase):
    def test_forms(self):
        form_data = {'headline': 'test', 'body_text': 'description of item Im selling', 'author: ben'}
        form = SellForm(data=form_data)
        self.assertEqual(form.is_valid(), True)

I am getting the following error:

ImportError: Failed to import test module: accounts.tests
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name
    __import__(name)
  File "/Users/benjamino/Desktop/myproject/myproject/accounts/tests.py", line 8
    form_data = {'headline': 'test', 'body_text': 'description of item Im selling', 'author: ben'}
                                                                                                 ^
SyntaxError: invalid syntax


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

FAILED (errors=1)
Destroying test database for alias 'default'...

Why is accounts.tests failing to import? The code above is located in my accounts/tests.py.

stephan
  • 2,293
  • 4
  • 31
  • 55

3 Answers3

0

This is a simple syntax error, as the message tells you. Your quoting is wrong in the last element of your dict: 'author: ben' should be 'author': 'ben'

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
0

The exception is clear on where the error is :

File "/Users/benjamino/Desktop/myproject/myproject/accounts/tests.py", line 8
    form_data = {'headline': 'test', 'body_text': 'description of item Im selling', 'author: ben'}
                                                                                                 ^
SyntaxError: invalid syntax

Take a better look at the form_data: {'headline': 'test', 'body_text': 'description of item Im selling', 'author: ben'} (you have included a string instead of a name: value pair in your dict)

Serafeim
  • 14,962
  • 14
  • 91
  • 133
0

It's clear from the exception itself that the error is in your syntax. The form data format should be {name : value} but in your case it's {'string : value'} and if that doesn't solved your problem,maybe this could help you Link

Community
  • 1
  • 1
Rakesh Kumar
  • 157
  • 1
  • 13