-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable inheritance #162
base: master
Are you sure you want to change the base?
Enable inheritance #162
Conversation
16553e8
to
d2e7e91
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments on approach design.
@@ -509,6 +509,7 @@ class TestSuite(Element): | |||
__test__ = False | |||
|
|||
testcase = TestCase | |||
root = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
root = None | |
root = JUnitXml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory that would be also my preferred way, but JUnitXml class is defined later in the same file and therefore can't be used here to initialize static member.
junitparser/junitparser.py
Outdated
cls = JUnitXml | ||
if TestSuite.root is not None and issubclass(TestSuite.root, JUnitXml): | ||
cls = TestSuite.root | ||
result = cls() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This then simplifies to
cls = JUnitXml | |
if TestSuite.root is not None and issubclass(TestSuite.root, JUnitXml): | |
cls = TestSuite.root | |
result = cls() | |
result = TestSuite.root() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To align with other places, TestSuite.root
should be accessed as self.root
.
junitparser/xunit2.py
Outdated
|
||
def __init__(self, name=None): | ||
super().__init__(name) | ||
TestSuite.root = JUnitXml | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be done similar to testcase
, or is root
different?
def __init__(self, name=None): | |
super().__init__(name) | |
TestSuite.root = JUnitXml | |
root = JUnitXml | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
root
is different, see comment
junitparser/junitparser.py
Outdated
@@ -33,7 +33,7 @@ def write_xml(obj, file_or_filename: Optional[Union[str, IO]] = None, *, pretty: | |||
xml = parseString(text) # nosec | |||
content = xml.toprettyxml(encoding="utf-8") | |||
if isinstance(file_or_filename, str): | |||
with open(file_or_filename, encoding="utf-8", mode="wb") as xmlfile: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unrelated, please revert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that this is unrelated. Will revert if requested, but in my case it raises a ValueError "binary mode doesn't take an encoding argument". Suggestion?
e61b4f8
to
dc84d2e
Compare
Follow up on #143, now it should be possible to properly derive all 3 classes (JUnitXml, TestSuite, TestCase) without loosing information while e.g. adding 2 testsuites to each other.