Invalid XML report generated when the test has an Examples table with hedears that contain spaces

Description of Issue

When a .feature file contains an Examples table (typically used for Sceario Outlines) with column headers that contain space characters (e.g. "My Header") the generated XML report is invalid and unusable after the test is done runnning.

Given BDD aims to write tests as close to plain english is possible, it is useful to be able to define column headers with spaces in them as they are used as parameters in the test script.

Affected version(s)

0.3.0 and later

System information

  • OS: Windows
  • OS version: 10
  • Qt version: 5.15.2
  • Python version: 3.11.7

Steps to reproduce

  • Write a .feature test file that uses a Scenario Outline and a corresponding Examples table
  • In the Examples table, set one of the column headers to a label with at least one space character (e.g. My Header)
  • Run the test
  • Try to parse the genrated XML report (or check it with an XML validator tool online)
  • The XML should be invalid because some of its tags is a label with spaces which violates XML syntax rules

Alternatively, add a space to any of the headers in this test to reproduce the issue.

What is the current issue behavior?

An invalid XML report is generated and cannot be parsed after generation.

What is the expected behavior?

The expectation is that the generated XML report is valid.

Relevant logs and/or screenshots

Python console output when running the aforementionned pytest with the modification to one of the headers

xml.etree.ElementTree.ParseError: not well-formed (invalid token)

Possible fixes

The problematic line can be found here.

Since XML doesn't allow to have spaces in its tags, the Examples column headers need to be logged differently in the report. For example:

<headers>header1 | header with spaces | last header</headers>
<row>value1 | value2 | value3</row>
...
<row>value4 | value5 | value6</row>

Otherwise the spaces can be replaced by underscores or hyphens, granted this can be problematic depending on the processing one would like to do with the XML report.

Edited by Tal Mezheritsky