Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weiwei committed Apr 21, 2023
1 parent a1f652f commit e53c43b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
30 changes: 0 additions & 30 deletions junitparser/flavors/xunit2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,6 @@
class JUnitXml(junitparser.JUnitXml):
# Pytest and xunit schema doesn't have skipped in testsuites
skipped = None
def __init__(self, name=None):
super().__init__(name)
def __iter__(self):
return super().iterchildren(TestSuite)
def __iadd__(self, other):
if other._elem.tag == "testsuites":
for suite in other:
self.add_testsuite(suite)
elif other._elem.tag == "testsuite":
suite = TestSuite(name=other.name)
for case in other:
suite._add_testcase_no_update_stats(case)
self.add_testsuite(suite)
self.update_statistics()
@classmethod
def fromroot(cls, root_elem):
"""Constructs Junit objects from an elementTree root element."""
if root_elem.tag == "testsuites":
instance = cls()
elif root_elem.tag == "testsuite":
instance = TestSuite()
else:
raise junitparser.JUnitXmlError("Invalid format.")
instance._elem = root_elem
return instance

def update_statistics(self):
"""Update test count, time, etc."""
Expand Down Expand Up @@ -116,11 +91,6 @@ def system_err(self, value):
err = junitparser.SystemErr(value)
self.append(err)

def testsuites(self):
"""Iterates through all testsuites."""
for suite in self.iterchildren(TestSuite):
yield suite

class StackTrace(junitparser.System):
_tag = "stackTrace"

Expand Down
14 changes: 13 additions & 1 deletion tests/test_xunit2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import unittest
from junitparser.flavors.xunit2 import JUnitXml, StackTrace, TestSuite, TestCase, FlakyError, FlakyFailure, RerunError, RerunFailure
from junitparser.flavors.xunit2 import JUnitXml, TestSuite, TestCase, RerunFailure
from junitparser import Failure
from copy import deepcopy

Expand Down Expand Up @@ -82,3 +82,15 @@ def test_remove_case(self):
suite.add_testcase(test)
suite.remove_testcase(test)
self.assertEqual(list(iter(suite)), [])

class Test_JUnitXml(unittest.TestCase):
def test_init(self):
xml = JUnitXml("tests")
self.assertEqual(xml.name, "tests")
xml = JUnitXml("myname")
xml.update_statistics()
self.assertEqual(xml.skipped, None)
# errors="0"
self.assertNotEqual(xml.tostring().find(b"errors"), -1)
# "skipped" attribute doesn't exist
self.assertEqual(xml.tostring().find(b"skipped"), -1)

0 comments on commit e53c43b

Please sign in to comment.