<commit_before>Test Isolation
==============

Database transactions per scenario
----------------------------------

Each scenario is run inside a database transaction, just like your
regular TestCases.  So you can do something like:

.. code-block:: python

    @given(u'user "{username}" exists')
    def create_user(context, username):
        # This won't be here for the next scenario
        User.objects.create_user(username=username, password='<PASSWORD>')

And you don’t have to clean the database yourself.<commit_msg>Add note on Django TestCase impl to Isolation chapter<commit_after>Test Isolation
==============

Database transactions per scenario
----------------------------------

Each scenario is run inside a database transaction, just like Django does
it with the related TestCase implementation.  So you can do something like:

.. code-block:: python

    @given(u'user "{username}" exists')
    def create_user(context, username):
        # This won't be here for the next scenario
        User.objects.create_user(username=username, password='<PASSWORD>')

And you don’t have to clean the database yourself.

Troubleshooting
---------------

.. note::

    Users have reported that test isolation and loading fixtures works
    differently with different test runners (e.g. when the ``--simple``
    option is used).  This is likely related to the Django TestCase class
    configured for the runner.

    Be sure you understand which Django TestCase class is used in your
    case, and how it's implemented in Django. See the `runner module`_
    and Django's documentation on `Writing and running tests`_ for details.


.. _runner module: https://github.com/behave/behave-django/blob/main/behave_django/runner.py
.. _Writing and running tests: https://docs.djangoproject.com/en/stable/topics/testing/overview/
{'fraction_non_alphanumeric': 0.132569558101473, 'fraction_numerical': 0.0, 'mean_word_length': 3.235565819861432, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5157430', 'n_tokens_mistral': 479, 'n_tokens_neox': 453, 'n_words': 194}