diff --git a/junitparser/__init__.py b/junitparser/__init__.py index 6280143..b628c4d 100644 --- a/junitparser/__init__.py +++ b/junitparser/__init__.py @@ -1,4 +1,4 @@ from .junitparser import (JUnitXmlError, Attr, Element, JUnitXml, TestSuite, - Property, Skipped, Failure, Error, TestCase, Properties) + Property, Skipped, Failure, Error, TestCase, Properties, IntAttr, FloatAttr) -__version__ = "1.2.0" \ No newline at end of file +__version__ = "1.2.1" \ No newline at end of file diff --git a/junitparser/junitparser.py b/junitparser/junitparser.py index be1d4e7..ca1c770 100644 --- a/junitparser/junitparser.py +++ b/junitparser/junitparser.py @@ -72,7 +72,9 @@ class IntAttr(Attr): "Integer attributes" def __get__(self, instance, cls): result = super(IntAttr, self).__get__(instance, cls) - if result is None: + if result is None and \ + (isinstance(instance, JUnitXml) or + isinstance(instance, TestSuite)): instance.update_statistics() result = super(IntAttr, self).__get__(instance, cls) return int(result) if result else None @@ -86,7 +88,9 @@ class FloatAttr(Attr): "Float attributes." def __get__(self, instance, cls): result = super(FloatAttr, self).__get__(instance, cls) - if result is None: + if result is None and \ + (isinstance(instance, JUnitXml) or + isinstance(instance, TestSuite)): instance.update_statistics() result = super(FloatAttr, self).__get__(instance, cls) return float(result) if result else None diff --git a/test.py b/test.py index c08c758..1e6cabb 100644 --- a/test.py +++ b/test.py @@ -8,7 +8,8 @@ import unittest from copy import deepcopy from junitparser import (TestCase, TestSuite, Skipped, Failure, Error, Attr, - JUnitXmlError, JUnitXml, Property, Properties) + JUnitXmlError, JUnitXml, Property, Properties, IntAttr, + FloatAttr) from xml.etree import ElementTree as etree from io import open try: @@ -627,5 +628,20 @@ def test_properties_ne2(self): self.assertNotEqual(props1, props2) +class Test_Attrs(unittest.TestCase): + + def test_attr(self): + TestCase.text = Attr("text") + TestCase.int = IntAttr("int") + TestCase.float = FloatAttr("float") + element = TestCase("foo") + element.text = "foo" + element.int = 10 + element.float = 8.5 + self.assertEqual(element.text, "foo") + self.assertEqual(element.int, 10) + self.assertEqual(element.float, 8.5) + + if __name__ == '__main__': unittest.main()