Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Enable inheritance #162

wants to merge 2 commits into from

Conversation

FlTr
Copy link

@FlTr FlTr commented Feb 25, 2025

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.

@FlTr FlTr force-pushed the enable-inheritance branch from 16553e8 to d2e7e91 Compare February 25, 2025 08:15
Copy link
Collaborator

@EnricoMi EnricoMi left a 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not

Suggested change
root = None
root = JUnitXml

Copy link
Author

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.

Comment on lines 556 to 559
cls = JUnitXml
if TestSuite.root is not None and issubclass(TestSuite.root, JUnitXml):
cls = TestSuite.root
result = cls()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This then simplifies to

Suggested change
cls = JUnitXml
if TestSuite.root is not None and issubclass(TestSuite.root, JUnitXml):
cls = TestSuite.root
result = cls()
result = TestSuite.root()

Copy link
Collaborator

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.

Comment on lines 170 to 174

def __init__(self, name=None):
super().__init__(name)
TestSuite.root = JUnitXml

Copy link
Collaborator

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?

Suggested change
def __init__(self, name=None):
super().__init__(name)
TestSuite.root = JUnitXml
root = JUnitXml

Copy link
Author

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

@@ -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:
Copy link
Collaborator

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.

Copy link
Author

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?

@FlTr FlTr force-pushed the enable-inheritance branch from e61b4f8 to dc84d2e Compare February 25, 2025 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants