0👍
TransactionTestCase
helps you save an saving an entire DB flush per test, it expects you to start with an unmarred db, you are free to generate it using any fixture generator. TransactionTestCase
however leaves the database cluttered, django-nose helps you optimize it. django-nose however has another test runner FastFixtureTestCase
helps you optimize the setUp and tearDown.
As already said, you can use any fixture generation, if you want the goodness of django-nose use the FastFixtureTestCase
and it will help you optimize the IO time.
4👍
Latest version of Django Dynamic Fixture includes a Django Nose plugin to facilitate creating global fixtures. Check if that helps you.
- [Django]-How to have nested url namespaces with a dynamic first part in Django
- [Django]-Cannot assign "<SimpleLazyObject: <User: XXX>>": "Comment.user" must be a "MyProfile" instance
- [Django]-Display item numbers with django paginator.
- [Django]-AttributeError: 'CombinedExpression' object has no attribute 'default_alias'
1👍
FastFixtureTestCase is used for fast fixtures handling and it will not help in this situation at all.
Using django_dynamic_fixture or factory_boy (which I use personally) and always creating only as little objects as it is needed for tests, and even if it is possible – completely omit database (e.g. when testing only model methods not related to other models) is the fastest approach.
Also if database is what is slowing you down try to use regular database for testing. I know that sqlite in tests should be fast, because it is run in-memory and all that stuff, but it is just still much slower than normal postgres/mysql database. You can also enable REUSE_DB option in django-nose which will make tests startup and shutdown much faster.
- [Django]-Django Social Auth w/ Twitter: HTTP 401 Error (Unauthorized)
- [Django]-Django "migrate" consuming too much CPU
- [Django]-Add Property to Django Result Object
- [Django]-Placing a <select> field using Django templates with custom bootstrap styles
0👍
I’m not familiar with django-nose’s optimization features, but in answer to your first question, if you repeatedly need the same set of objects for a bunch of tests, I’d just make a utility method or standalone function you can call that creates those objects and returns them (or one of them from which you can get to the others).
- [Django]-Django Rest Framework regroup queryset by a category
- [Django]-Chinese django translations not working
- [Django]-Is there a way to install django with pip to point to a specific version of python in virtualenv
- [Django]-Django – decorators restrict "staff"
0👍
you can create a data API handling data creation.
class TestData(objects):
def create_a_book_with_author(self):
author1 = G(Author)
author2 = G(Author)
book = G(Book, author=[author1])
class BookModelTest(TestCase):
def setUp(self):
TestData().create_a_book_with_author()
self.book_obj = Book.objects.all()
def test_book_creation(self):
self.assertEquals(self.book_obj.count(), 1)
self.assertEquals(list(self.book_obj[0].author), [author1])
self.assertEquals(self.book_obj[0].title, book.title)
self.assertNotEquals(list(self.book_obj[0].author), [author1])
- [Django]-Django multiple contexts within a single view
- [Django]-Django: get current url path from actual current page
- [Django]-Get key value from display value from choices in Django