A.J.
A.J.

Reputation: 8985

Structuring Django Testing & Test wont run

I am new to django testing & I am trying to write some unit tests for my Django project but when i moved tests to a new folder. I am getting the following message.

Creating test database for alias 'default'...

----------------------------------------------------------------------
Ran 0 tests in 0.000s # <======== ATTENTION

OK
Destroying test database for alias 'default'...

The tests were passing successfully.

python manage.py test public --traceback

Old structure

project |
  public | #app
     tests.py|
  private | #app
     tests.py

New structure

project |
  public | #app
     tests|
        __init__.py
        test_users.py
        test_models.py
        test_forms.py
  private | #app
     tests.py

With the structure I am unable to run tests.

test_users.py

class UserGroupCase(TestCase):
    def setUp(self):
        super(TestCase, self).setUp()
        self.groups = ["Regular", "Photographer", "Blogist"]
        for group in self.groups:
            Group.objects.create(name=group)

    def test_adding_user_in_group(self):
        self.assertTrue(len(self.groups), 2)
        regular = Group.objects.get(name=self.groups[0])
        photographer = Group.objects.get(name=self.groups[1])
        blogist = Group.objects.get(name=self.groups[2])

        robo1 = MyUser.objects.get(username="robot1")

        regular.user_set.add(robo1)

Please help out what I am missing here.

Django1.5.1

Upvotes: 2

Views: 62

Answers (1)

A.J.
A.J.

Reputation: 8985

I have found the answer, Posting it here as it might be helpful for others. its related to DJANGO 1.5

You can add tests to test/anydir/anydir1/test_user.py, but import every test to tests/__init__.py up until django 1.5.

Also there is a test runner which will work the way unittest2 discovery work. This functionality has been integrated into django1.6.

Upvotes: 2

Related Questions