@@ -85,16 +85,24 @@ def pytest_addoption(parser, pluginmanager):
8585 default = True ,
8686 help = 'Don\' t upload coverage results on test failure'
8787 )
88+ group .addoption (
89+ '--codecov-exclude-junit-xml' ,
90+ action = 'store_false' ,
91+ dest = 'codecov_junit_xml' ,
92+ default = True ,
93+ help = 'Don\' t upload the junit xml file'
94+ )
8895
8996
9097class CodecovPlugin :
9198
9299 def upload_report (self , terminalreporter , config , cov ):
100+ option = config .option
93101 uploader = codecov .CodecovUploader (
94- config . option .codecov_slug ,
95- commit = config . option .codecov_commit ,
96- branch = config . option .codecov_branch ,
97- token = config . option .codecov_token ,
102+ option .codecov_slug ,
103+ commit = option .codecov_commit ,
104+ branch = option .codecov_branch ,
105+ token = option .codecov_token ,
98106 )
99107 uploader .write_network_files (git .ls_files ())
100108 from coverage .misc import CoverageException
@@ -110,14 +118,21 @@ def upload_report(self, terminalreporter, config, cov):
110118 terminalreporter .line ('' )
111119 return
112120
113- if config .option .codecov_dump :
121+ xmlpath = option .xmlpath if option .codecov_junit_xml else None
122+ if xmlpath and os .path .isfile (xmlpath ):
123+ uploader .add_junit_xml (xmlpath )
124+ has_junit_xml = True
125+ else :
126+ has_junit_xml = False
127+
128+ if option .codecov_dump :
114129 terminalreporter .section ('Prepared Codecov.io payload' )
115130 terminalreporter .write_line (uploader .get_payload ())
116131 return
117132
118133 terminalreporter .section ('Codecov.io upload' )
119134
120- if not config . option .codecov_slug :
135+ if not option .codecov_slug :
121136 terminalreporter .write_line (
122137 'ERROR: Failed to determine git repository slug. '
123138 'Cannot upload without a valid slug.' ,
@@ -126,24 +141,35 @@ def upload_report(self, terminalreporter, config, cov):
126141 )
127142 terminalreporter .line ('' )
128143 return
129- if not config . option .codecov_branch :
144+ if not option .codecov_branch :
130145 terminalreporter .write_line (
131146 'WARNING: Failed to determine git repository branch.' ,
132147 yellow = True ,
133148 bold = True ,
134149 )
135- if not config . option .codecov_commit :
150+ if not option .codecov_commit :
136151 terminalreporter .write_line (
137152 'WARNING: Failed to determine git commit.' ,
138153 yellow = True ,
139154 bold = True ,
140155 )
156+ if has_junit_xml and config .getini ('junit_family' ) != 'legacy' :
157+ terminalreporter .write_line (
158+ 'INFO: We recommend using junit_family=legacy with CodeCov.' ,
159+ blue = True ,
160+ bold = True ,
161+ )
162+
141163 terminalreporter .write_line (
142164 'Environment:\n '
143- f'Slug: { config . option .codecov_slug } \n '
144- f'Branch: { config . option .codecov_branch } \n '
145- f'Commit: { config . option .codecov_commit } \n '
165+ f'Slug: { option .codecov_slug } \n '
166+ f'Branch: { option .codecov_branch } \n '
167+ f'Commit: { option .codecov_commit } \n '
146168 )
169+ if has_junit_xml :
170+ terminalreporter .write_line (
171+ 'JUnit XML file detected and included in upload.\n '
172+ )
147173 try :
148174 terminalreporter .write_line ('Pinging codecov API...' )
149175 uploader .ping ()
@@ -178,6 +204,10 @@ def pytest_terminal_summary(self, terminalreporter, exitstatus, config):
178204
179205
180206def pytest_configure (config ): # pragma: no cover
207+ # NOTE: Don't report codecov results on worker nodes
208+ if hasattr (config , 'workerinput' ):
209+ return
210+
181211 # NOTE: if cov is missing we fail silently
182212 if config .option .codecov and config .pluginmanager .has_plugin ('_cov' ):
183213 config .pluginmanager .register (CodecovPlugin ())
0 commit comments