1616
1717import coverage
1818from coverage .data import CoverageData
19+ from coverage .misc import CoverageException
1920from coverage .sqldata import filename_suffix
2021
2122from . import CentralCovContextWarning
@@ -255,6 +256,15 @@ def summary(self, stream):
255256 total = self .cov .json_report (ignore_errors = True , outfile = output )
256257 stream .write ('Coverage JSON written to file %s\n ' % (self .cov .config .json_output if output is None else output ))
257258
259+ # Check that markdown and markdown-append don't point to same file
260+ if all (x in self .cov_report for x in ['markdown' , 'markdown-append' ]):
261+ markdown_file = self .cov_report ['markdown' ] or 'coverage.md'
262+ markdown_append_file = self .cov_report ['markdown-append' ] or 'coverage.md'
263+ if markdown_file == markdown_append_file :
264+ error_message = f"markdown and markdown-append options cannot point to the same file: '{ markdown_file } '."
265+ error_message += ' Please redirect one of them using :DEST (e.g. --cov-report=markdown:dest_file.md)'
266+ raise CoverageException (error_message )
267+
258268 # Produce Markdown report if wanted.
259269 if 'markdown' in self .cov_report :
260270 output = self .cov_report ['markdown' ] or 'coverage.md'
@@ -265,7 +275,7 @@ def summary(self, stream):
265275
266276 # Produce Markdown report if wanted, appending to output file
267277 if 'markdown-append' in self .cov_report :
268- output = self .cov_report ['markdown-append' ] or 'coverage-append .md'
278+ output = self .cov_report ['markdown-append' ] or 'coverage.md'
269279 with _backup (self .cov , 'config' ):
270280 with Path (output ).open ('a' ) as output_file :
271281 total = self .cov .report (ignore_errors = True , file = output_file , output_format = 'markdown' )
0 commit comments