Skip to content

Are scenarios run in a database transaction? #4

@JCapriotti

Description

@JCapriotti

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions