{% for test in tests %}
  <div class="test collapsible {{ test.status.category }}">
    <div class="title">
      {% block test_title scoped %}
      <div class="status badge {{ test.status.category }} {{ test.status.style|join(' ') }}">{{ test.status.word }}</div>
      <h3 class="test-name">{{ test.item.name }}</h3>
      <div class="duration">{{ test.phases|sum('report.duration')|timedelta }}</div>
      {% endblock %}
    </div>
    <div class="content">
      {% block test_content scoped %}
      {% if test.item.function.__doc__ %}
        <div class="documentation">
          {{ test.item.function.__doc__|cleandoc|rst|safe }}
        </div>
      {% endif %}
      <table class="metadata">
        {% block test_metadata scoped %}
        <tr>
          <td>Started</td>
          <td>{{ test.phases|map(attribute='call.start')|first|strftime('%Y-%m-%d %H:%M:%S') }}</td>
        </tr>
        <tr>
          <td>Ended</td>
          <td>{{ test.phases|map(attribute='call.stop')|list|last|strftime('%Y-%m-%d %H:%M:%S') }}</td>
        </tr>
        <tr>
          <td>Duration</td>
          <td>{{ test.phases|map(attribute='report.duration')|sum|timedelta }}</td>
        </tr>
        {% set markers = test.item.iter_markers()|list %}
        {% if markers %}
          <tr>
            <td>Markers</td>
            <td>
              {% for marker in markers %}
                <div class="marker">
                  <span class="marker-name badge">{{ marker.name }}</span>
                  <span class="marker-args">
                    {% for value in marker.args %}
                      {{ value|repr }}
                    {% endfor %}

                    {% for key, value in marker.kwargs.items() %}
                      {{ key }}={{ value|repr }}
                    {% endfor %}
                  </span>
                </div>
              {% endfor %}
            </td>
          </tr>
        {% endif %}
        {% if test.item.fixturenames %}
          <tr>
            <td>Fixtures</td>
            <td>
              {% for fixturename in test.item.fixturenames if not fixturename.startswith('_') %}
                <div class="badge fixturename">
                  {{ fixturename }}
                </div>
              {% endfor %}
            </td>
          </tr>
        {% endif %}
        {% endblock %}
      </table>
      {% for phase in test.phases if phase.report.longrepr %}
        <div class="repr">
          <pre>{{ phase.report.longrepr }}</pre>
        </div>
      {% endfor %}
      <div class="test-phases">
        {% set ns = namespace(used_sections=[]) %}
        {% for phase in test.phases %}
          {% set sections = phase.report.sections|rejectattr(0, 'in', ns.used_sections)|list %}
          <div class="collapsible phase {{ phase.report.when }} {{ phase.status.category }}">
            <div class="title">
              <div class="status {{ phase.status.category }} {{ phase.status.style|join(' ') }}"></div>
              <h4 class="phase-name">{{ phase.report.when|title }}</h4>
            </div>
            <div class="content">
              {% for section, content in sections %}
                {% set ns.used_sections = ns.used_sections + [section] %}
                <div class="section">
                  <h5 class="section-title">{{ section }}</h5>
                  <pre>{{ content|escape|replace('\r\n', '\n')|ansi|safe }}</pre>
                </div>
              {% endfor %}
            </div>
          </div>
        {% endfor %}
        </div>
      {% endblock %}
    </div>
  </div>
{% endfor %}
