I want to have different Testcase classes inside my test.py in my django project. One for Model testing (crud) one for view testing etc. I have the following classes
class EntryModelTest(TestCase):
LOG = logging.getLogger(__name__)
@classmethod
def setup_database(cls):
#database initialization
@classmethod
def setUpClass(cls):
super(EntryModelTest, cls).setUpClass()
cls.setup_database()
cls.myModel = MyModel.objects.get(pk=1)
#some queries (additions) that use things that were added in setup_database()
and a second testcase
class MyCalViewsTest(TestCase):
LOG = logging.getLogger(__name__)
@classmethod
def setup_database(cls):
#exactly the same code as above testcase(I know I could use Inheretiance. Will refactor)
@classmethod
def setUpClass(cls):
#The same as above testcase
cls.myModel = MyModel.objects.get(pk=1) #this gives the following error: DoesNotExist: PracticeData matching query does not exist.
The MyModel instance is created in setup_database method. I am not quite sure why. If the test database is destroyed after every testcase class is executed then the setup_database method should have recreated the MyModel instance with pk=1 so I would have existed. If it doesn't destroy the test database then the MyModel instance with pk=1 already exists so I shouldn't have any problems also. Any help would be appreciated.