title: What is the best way to parameterize a pytest function using a fixture that returns a list?
body: <p>Right now I have a test file that looks like this contrived example:</p>
  
  <pre><code>import pytest
  
  def colors():
      # Expensive operation
      return ['red', 'yellow', 'blue']
  
  @pytest.mark.parametrize('color', colors())
  def test_colors(color):
      assert color != 'mauve'
  </code></pre>
  
  <p>This works fine, but since <code>colors()</code> is an expensive operation, I'd like to take advantage of pytest's caching and make it a session scoped fixture. Furthermore, I'd also like to write other tests using it as a fixture like</p>
  
  <pre><code>def test_colors_list(colors):
      assert len(colors) == 3
  </code></pre>
  
  <p>Ideally, my test file would look something like</p>
  
  <pre><code>@pytest.fixture(scope='session')
  def colors():
      # Expensive operation
      return ['red', 'yellow', 'blue']
  
  @pytest.mark.parametrize('color', colors)
  def test_colors(color):
      assert color != 'mauve'
  
  def test_colors_list(colors):
      assert len(colors) == 3
  </code></pre>
  
  <p>But this results in an error so I'm not going about this correctly. </p>
  
  <p>Ideally, I would also like to reference other fixtures in <code>colors()</code>, as well as still parameterize <code>test_colors()</code> to generate multiple functions. </p>
  
  <p>What's the best way I should write these tests? </p>