Here is my test:
class FirstTestCase(TransactionTestCase):
@classmethod
def setUpTestData(cls):
Car.objects.create(id=10001)
def findAllCars(self):
print(list(Car.objects.all()))
this gives no errors, and the list is simply printed as [], when clearly it should be [10001]
I know tests aren't supposed to inlude print statements, this is just an easy way to illustrate that for some reason the object in setUpTestData is not being created. How can I get it to make this object?
setUpTestData is only run, if your test inherits from APITestCase but not from APITransactionTestCase:
from rest_framework.test import APITestCase
class ExampleTestCase(APITestCase):
@classmethod
def setUpTestData(cls):
print("This is setUpTestData")
def test_something(self):
print("This is the test")
self.assertTrue(True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With