mercredi 10 avril 2019

Why testing doesn't detect test.py's syntax errors? and help me fix a bug

I wrote a test code as below and it has some bugs, which I can't detect but my teacher said you have missed self somewhere in your code. That was like a hint that I couldn't find that. This is my code:

def HomeTests(TestCase):
    def setUp(self):
        board = Board.objects.create(
            title='Django', description='Django Desc')
        url = reverse('home')
        response = self.client.get(url)

    def home_test_view_status_code(self):
        self.assertEqual(response.status_code, 200)

    def home_test_func(self):
        view = resolve('/')
        self.assertEqual(view.func, home)

    def test_home_contains_link_to_topics_page(self):
        board_topics_url = reverse(
            'board_topics', kwargs={'id': board.pk})
        self.assertContains(response, 'href={0}'.format(board_topics_url))

Even if I run python manage.py test this code doesn't throw any error:

System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

please help me what I am doing wrong here. where should be self keyword? and why?

Then, I went to library and checked to find the bug and by mistake I added a 'p' in view = resolvep('/') and without knowing I run python manage.py test it showed this result:

C:\Users\Administrator\Desktop\Practice\board\src>python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

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

while checking back my code I saw I misspelt resolve, here I come upon this question why it didn't throw a syntax error after testing because resolve() was misspelt? Then I intentionally added an extra 'e' in self.clieent.get(url) and again no errors? Please help me understand this Thank you so much

Aucun commentaire:

Enregistrer un commentaire