python - TransactionManagementError:This is forbidden when an 'atomic' block is active while running unit test cases -
i getting error while trying run unit test case using pytest. works fine in project raises error while running test case.
my code following:
def saveevents(request, request_data): transaction.set_autocommit(autocommit=false) try: # here code except exception inst: transaction.rollback() # code transaction.commit() return i read solutions of type of questions, puzzled why not working pytest. please help.
if testing code manually manages transactions, should mark test follows:
@pytest.mark.django_db(transaction=true) def my_test(): ... see the pytest-django docs more info.
note may able restructure code , use with transaction.atomic(): inside try.. except block instead of doing manual transaction management. see django docs examples.
Comments
Post a Comment