64👍
Use django.test.TestCase
not unittest.TestCase
. And it works in all major versions of Django!
2👍
You can use the tearDown
method. It will be called after your test is run. You can delete all Blahs there.
- [Django]-Writing test cases for django models
- [Django]-How to update multiple fields of a django model instance?
- [Django]-How do I prevent fixtures from conflicting with django post_save signal code?
1👍
Make them in two different functions both are not test function. Finally call the dependent functions from one test function.
- [Django]-Django vs. Model View Controller
- [Django]-How to display uploaded images in "Change List" page in Django Admin?
- [Django]-Django settings per application – best practice?
0👍
Why not do the following? This accomplishes what you need without a significant change to your code.
class TestOneForManager(unittest.TestCase):
def testAddingBlah(self):
manager = Manager()
self.assertEquals(manager.getBlahs(), 0)
manager.addBlah(...)
self.assertEquals(manager.getBlahs(), 1)
class TestTwoForManager(unittest.TestCase):
def testAddingBlahInDifferentWay(self):
manager = Manager()
self.assertEquals(manager.getBlahs(), 0)
manager.addBlahInDifferentWay(...)
self.assertEquals(manager.getBlahs(), 1)
Edit. The “reset on TestCase” feature gives you complete control.
-
Many test methods in a single TestCase are good when you have test cases that don’t interfere with each other.
-
Few test methods in a single TestCase are good when you have test cases that interfere with each other.
You can choose which model applies to your tests by grouping your test methods in one or many TestCases. You have total and complete control.
- [Django]-Id field in Model Django
- [Django]-Django character set with MySQL weirdness
- [Django]-Managing static files for multiple apps in Django
0👍
For clearing non-default databases, add multi_db = True
in the class
eg
class MyTestCase(django.test.TestCase)
multi_db = True
def test_one(self):
self.assertTrue(True)
- [Django]-Django runserver permanent
- [Django]-Django Call Class based view from another class based view
- [Django]-RequestDataTooBig Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE