question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Are scenarios run in a database transaction?

See original GitHub issue

Hello, I have some test cases that appear to be failing because of how the database is reset after each scenario. Specifically, database sequences are not being reset. I stumbled on what seems like conflicting statements in the documentation.

From https://pythonhosted.org/behave-django/usage.html#database-transactions-per-scenario

Each scenario is run inside a database transaction, just like your regular TestCases

From the last paragraph of https://pythonhosted.org/behave-django/usage.html#fixture-loading

This is because Django’s LiveServerTestCase resets the test database after each scenario

Now if you dig into LiveServerTestCase via https://docs.djangoproject.com/en/1.9/topics/testing/tools/

LiveServerTestCase does basically the same as TransactionTestCase

Or, LiveServerTestCase is a subclass of TransactionTestCase. And further down…

  • A TransactionTestCase resets the database after the test runs by truncating all tables. A TransactionTestCase may call commit and rollback and observe the effects of these calls on the database.
  • A TestCase, on the other hand, does not truncate tables after a test. Instead, it encloses the test code in a database transaction that is rolled back at the end of the test. This guarantees that the rollback at the end of the test restores the database to its initial state.

My first question is… is it correct that that behave-django is using a LiveServerTestCase, which means there is no database transaction happening?

Second, is there any way to change what happens when the database is reset? i.e. specify that the TestCase transaction behavior be used. Or alternatively, allow support modifying things like TransactionTestCase.reset_sequences

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JCapriotticommented, Apr 14, 2016

Yep, sorry I forgot to reply earlier; I saw a shiny object that day.

It is good to close.

0reactions
bittnercommented, Jul 9, 2019

As mentioned by a friendly user in our Gitter chat room a solution approach may be to set serialized_rollback = True on the testcase.

See also

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transaction Scenarios - COM & .NET Component ... - O'Reilly
Consider an application that comprises just one component instance, an object that processes a client's request and accesses a single resource (such as...
Read more >
What is a database transaction? - Fauna
A database transaction is a sequence of multiple operations performed on a database, and all served as a single logical unit of work ......
Read more >
Database SpecFlow Scenarios and TransactionScope
My team has been using SpecFlow to verify that our data access components are working correctly. In an effort to write repeatable tests...
Read more >
In-Memory OLTP Overview and Usage Scenarios
This article includes an overview of the technology and outlines usage scenarios for In-Memory OLTP.
Read more >
Interactive Application Transaction Processing Scenarios
The runtime engine commits database operations. To include two connected forms in the same transaction boundary, you must activate transaction processing ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found