-
Notifications
You must be signed in to change notification settings - Fork 55
Enable inheritance #162
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
Conversation
16553e8 to
d2e7e91
Compare
EnricoMi
left a comment
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.
junitparser/junitparser.py
Outdated
| __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.
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.
I think we then can turn this static member into a class member, code should work either way
| root = None |
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.
|
|
||
| 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
| 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?
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.
You are right, given content is bytes and mode="wb", the encoding="utf-8" is not needed.
Strange we do not see this in tests. Is that specific to some Python version?
Do you mind opening a new pull request where tests fail on this issue and then fix it as above?
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.
Can't tell you. But I can see it locally but not in my project CI instance.
Will revert here and try to manage a separate PR.
e61b4f8 to
dc84d2e
Compare
dc84d2e to
4a26fa3
Compare
EnricoMi
left a comment
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.
Looks good!
Can you add some tests that would fail without this change (when adding or iterating over testsuites)?
|
Added tests to verify iteration and add operations return the correct, potentially inherited, TestSuites / JUnitXml instances. |
EnricoMi
left a comment
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.
LGTM! Thanks for the contribution!
|
@weiwei any objections? |
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.