Skip to content

Conversation

@FlTr
Copy link
Contributor

@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.

__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
Contributor 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.

Copy link
Collaborator

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

Suggested change
root = None

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
Contributor 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

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
Contributor 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?

Copy link
Collaborator

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?

Copy link
Contributor Author

@FlTr FlTr Mar 17, 2025

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.

@FlTr FlTr force-pushed the enable-inheritance branch from e61b4f8 to dc84d2e Compare February 25, 2025 11:06
@FlTr FlTr requested a review from EnricoMi March 14, 2025 09:13
@github-actions
Copy link

github-actions bot commented Mar 14, 2025

Test Results

   48 files  ± 0     48 suites  ±0   3m 25s ⏱️ +2s
  124 tests + 2    124 ✅ + 2    0 💤 ±0  0 ❌ ±0 
5 952 runs  +96  5 781 ✅ +96  171 💤 ±0  0 ❌ ±0 

Results for commit c33ecdc. ± Comparison against base commit bca6112.

♻️ This comment has been updated with latest results.

@FlTr FlTr force-pushed the enable-inheritance branch from dc84d2e to 4a26fa3 Compare March 17, 2025 13:27
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.

Looks good!

Can you add some tests that would fail without this change (when adding or iterating over testsuites)?

@FlTr
Copy link
Contributor Author

FlTr commented Mar 18, 2025

Added tests to verify iteration and add operations return the correct, potentially inherited, TestSuites / JUnitXml instances.

@FlTr FlTr requested a review from EnricoMi March 18, 2025 15:11
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.

LGTM! Thanks for the contribution!

@EnricoMi
Copy link
Collaborator

@weiwei any objections?

@weiwei weiwei merged commit f31c7a7 into weiwei:master Jun 22, 2025
38 checks passed
@FlTr FlTr deleted the enable-inheritance branch July 7, 2025 08:39
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.

3 participants