Skip to content

Commit

Permalink
introduced f-strings
Browse files Browse the repository at this point in the history
converted to more modern f-strings
  • Loading branch information
Mark Mayo authored and ionelmc committed May 21, 2023
1 parent 0d63ede commit 76fb2a6
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 148 deletions.
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def run(self):
with open(join(dirname(__file__), 'src', 'pytest-cov.pth'), 'w') as fh:
with open(join(dirname(__file__), 'src', 'pytest-cov.embed')) as sh:
fh.write(
'import os, sys;'
'exec(%r)' % sh.read().replace(' ', ' ')
f"import os, sys;exec({sh.read().replace(' ', ' ')!r})"
)


Expand Down
14 changes: 7 additions & 7 deletions src/pytest_cov/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,19 @@ def summary(self, stream):

# Output coverage section header.
if len(self.node_descs) == 1:
self.sep(stream, '-', 'coverage: %s' % ''.join(self.node_descs))
self.sep(stream, '-', f"coverage: {''.join(self.node_descs)}")
else:
self.sep(stream, '-', 'coverage')
for node_desc in sorted(self.node_descs):
self.sep(stream, ' ', '%s' % node_desc)
self.sep(stream, ' ', f'{node_desc}')

# Report on any failed workers.
if self.failed_workers:
self.sep(stream, '-', 'coverage: failed workers')
stream.write('The following workers failed to return coverage data, '
'ensure that pytest-cov is installed on these workers.\n')
for node in self.failed_workers:
stream.write('%s\n' % node.gateway.id)
stream.write(f'{node.gateway.id}\n')

# Produce terminal report if wanted.
if any(x in self.cov_report for x in ['term', 'term-missing']):
Expand All @@ -178,7 +178,7 @@ def summary(self, stream):
with _backup(self.cov, "config"):
total = self.cov.report(ignore_errors=True, file=_NullFile)
if annotate_dir:
stream.write('Coverage annotated source written to dir %s\n' % annotate_dir)
stream.write(f'Coverage annotated source written to dir {annotate_dir}\n')
else:
stream.write('Coverage annotated source written next to source\n')

Expand All @@ -187,14 +187,14 @@ def summary(self, stream):
output = self.cov_report['html']
with _backup(self.cov, "config"):
total = self.cov.html_report(ignore_errors=True, directory=output)
stream.write('Coverage HTML written to dir %s\n' % (self.cov.config.html_dir if output is None else output))
stream.write(f'Coverage HTML written to dir {self.cov.config.html_dir if output is None else output}\n')

# Produce xml report if wanted.
if 'xml' in self.cov_report:
output = self.cov_report['xml']
with _backup(self.cov, "config"):
total = self.cov.xml_report(ignore_errors=True, outfile=output)
stream.write('Coverage XML written to file %s\n' % (self.cov.config.xml_output if output is None else output))
stream.write(f'Coverage XML written to file {self.cov.config.xml_output if output is None else output}\n')

# Produce json report if wanted
if 'json' in self.cov_report:
Expand All @@ -213,7 +213,7 @@ def summary(self, stream):
# Coverage.lcov_report doesn't return any total and we need it for --cov-fail-under.
total = self.cov.report(ignore_errors=True, file=_NullFile)

stream.write('Coverage LCOV written to file %s\n' % (self.cov.config.lcov_output if output is None else output))
stream.write(f'Coverage LCOV written to file {self.cov.config.lcov_output if output is None else output}\n')

return total

Expand Down
6 changes: 3 additions & 3 deletions src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ def pytest_runtestloop(self, session):
try:
self.cov_total = self.cov_controller.summary(self.cov_report)
except CoverageException as exc:
message = 'Failed to generate report: %s\n' % exc
message = f'Failed to generate report: {exc}\n'
session.config.pluginmanager.getplugin("terminalreporter").write(
'WARNING: %s\n' % message, red=True, bold=True)
f'WARNING: {message}\n', red=True, bold=True)
warnings.warn(CovReportWarning(message))
self.cov_total = 0
assert self.cov_total is not None, 'Test coverage should never be `None`'
Expand All @@ -320,7 +320,7 @@ def pytest_terminal_summary(self, terminalreporter):
if self._disabled:
if self.options.no_cov_should_warn:
message = 'Coverage disabled via --no-cov switch!'
terminalreporter.write('WARNING: %s\n' % message, red=True, bold=True)
terminalreporter.write(f'WARNING: {message}\n', red=True, bold=True)
warnings.warn(CovDisabledWarning(message))
return
if self.cov_controller is None:
Expand Down
Loading

0 comments on commit 76fb2a6

Please sign in to comment.