0👍
✅
After like two days I got a solution to my Qts..
In order to retain your data after a success unit test you have to subclass a TestCase from unittest otherwise to perform auto rollback then import TestCase from django.test.
3👍
The TestCase
class wraps each test in a transaction, which is rolled back after the transaction (see the relevant documentation).
Even if test_registration
successfully registers a user, it won’t be available in test_login
.
I would suggest creating a user for testing in a setUpClass
method.
- [Django]-Automatically assigning model field values in Django
- [Django]-Overriding Django Admin's main page? – Django
- [Django]-Django : How to distinct by DateTimeField with ignoring the second / millisecond difference
- [Django]-How can i make a 'view_count' in django-rest-framework?
- [Django]-Django – TypeError: object of type 'NoneType' has no len() occurred while doing Pagination
1👍
In order to do this, you need to use import unittest instead of from django.test import TestCase
And in your unit test class extends TestCase with unittest.TestCase
see the example below
import unittest
class MyTest(unittest.TestCase):
.......
Source:stackexchange.com