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

implement flavors #108

Merged
merged 12 commits into from
Apr 24, 2023
Merged

implement flavors #108

merged 12 commits into from
Apr 24, 2023

Conversation

weiwei
Copy link
Owner

@weiwei weiwei commented Apr 20, 2023

This is to address #101, as well as other frequent xml schema support requirements.

I've thought about JunitXml(flavor='pytest'), but typings will be tricky when it comes to dealing with elements like TestSuite and TestCase, which will also be different with those in the "standard" implementation, For example, autocompletion won't know this TestCase now has a rerun_errors() method.

With implementation in this PR, a flavor and its elements are imported and used separately, and autocompletion works on each case.

from junitparser.flavors.pytest_xml import JUnitXml, TestSuite, TestCase, RerunFailure

# Create cases
case1 = TestCase('case1') # A pytest case
case1.group = 'Group1' # pytest specific
case1.add_rerun_result(RerunFailure('Server Error', '500') # pytest specific

# Create suite and add cases
suite = TestSuite('suite1') # A pytest suite
suite.add_property('build', '55')
suite.add_testcase(case1)
suite.remove_testcase(case2)

# Add suite to JunitXml
xml = JUnitXml() # A pytest JUnitXml class
xml.add_testsuite(suite)
xml.write('junit.xml')

Also address #97 by adding rudimentary types

SystemOut, SystemErr, TestCase as OrigTestCase, System


class PytestXml(JUnitXml):
Copy link
Owner Author

Choose a reason for hiding this comment

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

Maybe name it to JUnitXml as well. Could result in less cognitive load. Flavors are separated by file names already.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, this should be

Suggested change
class PytestXml(JUnitXml):
class JUnitXml(junitparser.JUnitXml):

Then user code looks identical, no matter which import they use:

from junitparser.junitparser import JUnitXml
from junitparser.flavors.pytest_xml import JUnitXml

@codecov
Copy link

codecov bot commented Apr 20, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.27 🎉

Comparison is base (314d69c) 97.96% compared to head (284189c) 98.24%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #108      +/-   ##
==========================================
+ Coverage   97.96%   98.24%   +0.27%     
==========================================
  Files           6        8       +2     
  Lines        1231     1424     +193     
==========================================
+ Hits         1206     1399     +193     
  Misses         25       25              
Impacted Files Coverage Δ
junitparser/cli.py 50.00% <ø> (ø)
tests/test_cli.py 100.00% <ø> (ø)
tests/test_fromfile.py 98.75% <ø> (-0.03%) ⬇️
tests/test_general.py 99.11% <ø> (-0.01%) ⬇️
junitparser/__init__.py 100.00% <100.00%> (ø)
junitparser/junitparser.py 99.12% <100.00%> (ø)
junitparser/xunit2.py 100.00% <100.00%> (ø)
tests/test_xunit2.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@weiwei weiwei requested a review from EnricoMi April 20, 2023 08:17
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.

I like the idea of using packages to select the flavour, re-exporting unchanged classes and deriving changed classes.

I think the xml is redundant in the pytest_xml flavour name.

SystemOut, SystemErr, TestCase as OrigTestCase, System


class PytestXml(JUnitXml):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, this should be

Suggested change
class PytestXml(JUnitXml):
class JUnitXml(junitparser.JUnitXml):

Then user code looks identical, no matter which import they use:

from junitparser.junitparser import JUnitXml
from junitparser.flavors.pytest_xml import JUnitXml

# -*- coding: utf-8 -*-

import unittest
from junitparser.flavors.pytest_xml import PytestXml, TestSuite, TestCase, FlakyError, FlakyFailure, RerunError, RerunFailure
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer

from junitparser.pytest_xml import ...

Copy link
Owner Author

Choose a reason for hiding this comment

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

Less nesting is good. Keeping the root clean may be also worth it. Let me think this over.

@weiwei weiwei force-pushed the flavors branch 2 times, most recently from e53c43b to 0bf31a1 Compare April 21, 2023 14:35
@weiwei weiwei marked this pull request as ready for review April 22, 2023 04:15
Copy link
Owner Author

Choose a reason for hiding this comment

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

No code change. Just that orders need to be adjusted for the type hints to work.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Format change curtesy of black.

@weiwei weiwei merged commit 5648005 into master Apr 24, 2023
@weiwei weiwei deleted the flavors branch April 24, 2023 15:32
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 great!

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