TransactionManagementError:This is forbidden when an 'atomic' block is active while running unit test cases

Viewed 1171

I am getting this error while I am trying to run unit test case using pytest. It works fine in my project but raises an error while running test case.

My code is as following:

def saveEvents(request, request_data):
    transaction.set_autocommit(autocommit=False)
    try:
        # here is my code
    except Exception as inst:
        transaction.rollback()
        # code
    transaction.commit()
    return something

I read all the solutions of this type of questions, but I am puzzled why its not working with pytest. Please help.

1 Answers
Related