1

I use xunitmerge to merge all pytest junit xml output into one single junit xml. Command used to run pytest and merge are below:

for i in `ls  test_*`
do
test_suit=$(echo $i |cut -d'.' -f1)
py.test $i --tb=long --html=Reports/${test_suit}.html --junitxml=Reports/${test_suit}.xml -vv
done

xunitmerge Reports/*.xml Reports/discovery.xml

Here, all xml are merged to one single xml file.

Is there any tool to convert multiple py.test html files to one single html report file?

Note: when I run py.test without specifying test_ it triggers all files starting with test_ automatically. But since I use the ordering plugin, Order in multiple files I can't use to run py.test without specifying specific test case file.

DV82XL
  • 5,350
  • 5
  • 30
  • 59
Naggappan Ramukannan
  • 2,564
  • 9
  • 36
  • 59

1 Answers1

0

You can use XSLT for that by:

  • either merging your XHTML reports to one master HTML file, as explained here for instance
  • or producing an HTML output from your merged XML output, as described there for example

For instance, let assume that you have the following XML file (catalog.xml):

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <item>
    <name>A great book</name>
    <price>10</price>
  </item>
</catalog>

You can create an XSL template (catalog.xsl):

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My Catalog</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th>Name</th>
      <th>Price</th>
    </tr>
    <xsl:for-each select="catalog/item">
    <tr>
      <td><xsl:value-of select="name"/></td>
      <td><xsl:value-of select="price"/></td>
    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

Then, the only thing you have to do is to reference your XSL template in your XML file.
Finally, your XML file should look like:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="catalog.xsl"?>
<catalog>
  <item>
    <name>A great book</name>
    <price>10</price>
  </item>
</catalog>

Open your XML file in a browser and it'll be rendered using the XSL template!

Community
  • 1
  • 1
filaton
  • 2,257
  • 17
  • 27
  • How can i use XSLT is there any tool? when i checked the link provided to convert final xml to html they have just provided 2 xml one input (my case) 2nd one output xslt file which can be viewed as html. How can do this conversion its not mentioned in the link provided – Naggappan Ramukannan Apr 19 '16 at 11:22
  • I think I need a template(xslt) to convert junit xml to proper html. Then later on we can use both the xml file and use a python script to convert – Naggappan Ramukannan Apr 19 '16 at 12:28
  • No need to do strictly a "conversion", just link your XSL template in your XML file (see my updated answer). – filaton Apr 19 '16 at 12:57