title: pytest nested parametrization with tree-like data
body: <p>Using pytest, I'm trying to test a tree like hierarchical scenario.
  Lets use a document structure as an example:</p>
  
  <pre><code>Document --- Chapter --- Paragraph
         1   n        1   n
  </code></pre>
  
  <p>Where a document contains multiple chapters; a chapter contains multiple paragraphs.</p>
  
  <p>When starting testing a new document, some setup code need to be run; when a new chapter is started, some other setup code need to be run; and the same for paragraph.</p>
  
  <p>Written as pseudo code:</p>
  
  <pre><code>for doc in documents:
      setup_doc(doc)
      for chapter in doc.chapters:
          setup_chapter(chapter)
          for paragraph in chapter.paragraphs:
              setup_paragraph(paragraph)
              test_it(doc, chapter, paragraph)
              teardown_paragraph(paragraph)
          teardown_chapter(chapter)
      teardown_doc(doc)
  </code></pre>
  
  <p>If we have the following data:</p>
  
  <pre><code>Document Alpha
     chapter A
        Paragraph A1
        Paragraph A2
     chapter B
        Paragraph B1
  </code></pre>
  
  <p>I would expect the collected test cases to be:</p>
  
  <pre><code>test_it[Alpha, A, A1]
  test_it[Alpha, A, A2]
  test_it[Alpha, B, B1]
  </code></pre>
  
  <p>I've tried different combinations of pytest_generate_tests, class scenarios, fixtures and parametrized test functions, but have not been able to achieve this.</p>
  
  <p>Any pointers would be greatly appreciated.</p>