title: Django Pytest. Use database entries in parametrize
body: <p>I want to have a test for data that will use real data from DB.</p>
  <p>The goal is to go through all the entries of a table <code>Foo</code> and apply some test logic on each entry. Ideally is to use <code>parametrize</code> for that but I am a bit struggling with DB access to <code>parametrize</code>.</p>
  <p>What I do so far:</p>
  <p><strong>tests.py</strong></p>
  <pre><code>import pytest
  from app.models import Foo
  
  pytestmark = pytest.mark.django_db
  
  @pytest.fixture(scope='session')
  def django_db_setup():
      settings.DATABASES['default'] = {
          'ENGINE': 'django.db.backends.mysql',
          'NAME': os.environ['DB_NAME'],
          'USER': os.environ['DB_USER'],
          'PASSWORD': os.environ['DB_PASSWORD'],
          'HOST': 'localhost',
      }
  
  @pytest.mark.django_db
  class TestFoo:
      @pytest.mark.parametrize('foo', Foo.objects.all())
      def test_foo_objects(self, foo):
          assert foo.is_ok
  </code></pre>
  <p>Eventually I get</p>
  <blockquote>
  <p>E   RuntimeError: Database access not allowed, use the &quot;django_db&quot; mark, or the &quot;db&quot; or &quot;transactional_db&quot; fixtures to enable it.</p>
  </blockquote>
  <p>However, if DB-access is not used in <code>parametrize</code> - it works. I.e inside <code>test_foo_objects</code> DB-access is allowed.</p>
  <p>So the question is how to allow <code>parametrize</code> use DB as well?</p>