title: pytest, how to keep database change between test
body: <p>I'm using the following inside <code>conftest.py</code> </p>
  
  <pre><code>@pytest.fixture(scope='session')
  def django_db_setup():
      settings.DATABASES['default'] = {
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
          'NAME': 'my_db',
          'HOST': 'localhost',
      }
  </code></pre>
  
  <p>it reads data from existing DB fine.
  Now I want to run two tests and want the change I made in preceding tests to persist until test2 (until the whole tests in the file is finished)</p>
  
  <pre><code>def test_1():
  
      user = User.objects.get(email='a@example.com')
      user.username = 'hello'
      user.save()
  
  
  def test_2():
  
      user = User.objects.get(email='a@example.com')
      print(user.username)        # expect 'hello' but it's not
  </code></pre>
  
  <ul>
  <li>there's scope `session/module' and wonder what it means, session means the whole test run?</li>
  </ul>
  
  <p>Following is what I have tried, but doesn't work..
  (from bottom of <a href="https://github.com/pytest-dev/pytest-django/blob/master/docs/database.rst" rel="nofollow noreferrer">https://github.com/pytest-dev/pytest-django/blob/master/docs/database.rst</a>)</p>
  
  <p>In contest.py</p>
  
  <pre><code>@pytest.fixture(scope='session')
  def django_db_setup():
      settings.DATABASES['default'] = {
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
          'NAME': 'my_db',
          'HOST': 'localhost',
      }
  
  @pytest.fixture
  def db_no_rollback(request, django_db_setup, django_db_blocker):
      # https://github.com/pytest-dev/pytest-django/blob/master/docs/database.rst
      django_db_blocker.unblock()
      request.addfinalizer(django_db_blocker.restore)
  </code></pre>
  
  <p>in test.py</p>
  
  <pre><code>def test_1(db_no_rollback):
  
      user = User.objects.get(email='a@example.com')
      user.username = 'hello'
      user.save()
  
  
  def test_2(db_no_rollback):
  
      user = User.objects.get(email='a@example.com')
      print(user.username)        # expect 'hello' but it's not
  </code></pre>