Django Test Object Created Is Empty
I am trying to follow instructions from the Django documentation: https://docs.djangoproject.com/en/3.2/topics/testing/overview/ However when I try to create the object for the tes
Solution 1:
You need to use setUp
and not setup
as the function for setting up your test case.
You also don't need to call save()
if you use create()
.
An alternative you could make use of is setUpTestData()
This technique allows for faster tests as compared to using
setUp()
.
classTestURLShortener(TestCase):@classmethoddefsetUpTestData(cls):
# Set up data for the whole TestCase
cls.obj = ShortURL.objects.create(original_url=url, short_url='zqSkSQ', time_date_created=time, count=2)
...
defsetUp(self):
self.client = Client()
deftest_obj_type(self):
self.assertTrue(isinstance(self.obj, ShortURL))
Post a Comment for "Django Test Object Created Is Empty"