[Django]-Posting data using Django unit testing not saving to backend

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.

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):
    .......

Leave a comment