title: Using @pytest.fixture(scope="module") with @pytest.mark.asyncio
body: <p>I think the example below is a really common use case:</p>
  
  <ol>
  <li>create a connection to a database <em>once</em>, </li>
  <li>pass this connection around to test which insert data</li>
  <li>pass the connection to a test which verifies the data.</li>
  </ol>
  
  <p>Changing the scope of <code>@pytest.fixture(scope="module")</code> causes <code>ScopeMismatch: You tried to access the 'function' scoped fixture 'event_loop' with a 'module' scoped request object, involved factories</code>.</p>
  
  <p>Also, the <code>test_insert</code> and <code>test_find</code> coroutine do not need the event_loop argument because the loop is accessible already by passing the connection.</p>
  
  <p>Any ideas how to fix those two issues?</p>
  
  <pre class="lang-py prettyprint-override"><code>import pytest
  
  @pytest.fixture(scope="function")  # &lt;-- want this to be scope="module"; run once!
  @pytest.mark.asyncio
  async def connection(event_loop):
      """ Expensive function; want to do in the module scope. Only this function needs `event_loop`!
      """
      conn await = make_connection(event_loop)
      return conn
  
  
  @pytest.mark.dependency()
  @pytest.mark.asyncio
  async def test_insert(connection, event_loop):  # &lt;-- does not need event_loop arg
      """ Test insert into database.
  
          NB does not need event_loop argument; just the connection.
      """
      _id = 0
      success = await connection.insert(_id, "data")
      assert success == True
  
  
  @pytest.mark.dependency(depends=['test_insert'])
  @pytest.mark.asyncio
  async def test_find(connection, event_loop):  # &lt;-- does not need event_loop arg
      """ Test database find.
  
          NB does not need event_loop argument; just the connection.
      """
      _id = 0
      data = await connection.find(_id)
      assert data == "data"
  </code></pre>