Test Cases without making changes to database

Hello everyone,

Is there any way to run test cases without adding, deleting or updating database?
For example, if I want to add a record in a DocType in test case, I do not want that record to be added in database.

Thank You in advance!

@aldoblack, there’s no way to avoid database writing in tests.

What frappe allow you is define an test database, where during tests your I/O will be done there

I found a way. I created this function inside Test class:

def tearDown(self):
    frappe.db.sql('ROLLBACK;')

And every SQL transaction will be rolled back.

@aldoblack that’s great, but I know later you will found issues with that!

Really? How so?

How do you test interconnected cases via this method? Clone your system and test. That easy…

@aldoblack when you run really long tests, you will fight with the maximun number of transactions in memory

After 200.000 or everything will fail, or it will commit into the database.

Sometime we do think it dont will reach that value, but that is not true, some transaction like Invoices, make writes in many places, each write, is counted as one, and not the full transaction.

Also like @Tufan_Kaynak2 asked, what happens if you have around 100 - Leads, and whants to generate tests from these leads, generating a random number of transaction, from lead to payments? You will reach thar number really faster.

Also what happens, if you want to bulk load handreds of items, and try generation transactions on top of they, again, if you fight that number, faster.