inertiajs / inertia-django

The Django adapter for Inertia.js
MIT License
326 stars 32 forks source link

Setup method not working while testing #41

Open pvpmartins opened 9 months ago

pvpmartins commented 9 months ago

So, I would like to use the very handy setup method in order to make some test cases without repeating myself.

class RegisterViewTest(InertiaTestCase):
    def setUp(self):
        # Setup run before every test method.
        self.test_user = User.objects.create_user(username='testuser', password='testpassword')

But unfortunately i get this error:

Traceback (most recent call last):
  File "/home/pvpmartins/nutrify/myenv/lib/python3.11/site-packages/inertia/test.py", line 25, in tearDown
    self.mock_inertia.stop()
    ^^^^^^^^^^^^^^^^^
AttributeError: 'RegisterViewTest' object has no attribute 'mock_inertia'

======================================================================
ERROR: test_register_and_login_pro_user (nutrifyapp.tests.RegisterViewTest.test_register_and_login_pro_user)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pvpmartins/nutrify/myenv/lib/python3.11/site-packages/inertia/test.py", line 25, in tearDown
    self.mock_inertia.stop()
    ^^^^^^^^^^^^^^^^^
AttributeError: 'RegisterViewTest' object has no attribute 'mock_inertia'
CalElAn commented 3 months ago

Hi I'm also facing this error. Were you able to solve it?

Edit: I was able to solve it like by calling InertiaTestCase.setUp(self) in the setUp method like so

def setUp(self):
    InertiaTestCase.setUp(self)