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

introduced f-strings #572

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 lcov report if wanted.
if 'lcov' in self.cov_report:
Expand All @@ -206,7 +206,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 @@ -305,9 +305,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 @@ -319,7 +319,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