Skip to content

Commit 76fb2a6

Browse files
Mark Mayoionelmc
Mark Mayo
authored andcommittedMay 21, 2023
introduced f-strings
converted to more modern f-strings
1 parent 0d63ede commit 76fb2a6

File tree

4 files changed

+147
-148
lines changed

4 files changed

+147
-148
lines changed
 

‎setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ def run(self):
8080
with open(join(dirname(__file__), 'src', 'pytest-cov.pth'), 'w') as fh:
8181
with open(join(dirname(__file__), 'src', 'pytest-cov.embed')) as sh:
8282
fh.write(
83-
'import os, sys;'
84-
'exec(%r)' % sh.read().replace(' ', ' ')
83+
f"import os, sys;exec({sh.read().replace(' ', ' ')!r})"
8584
)
8685

8786

‎src/pytest_cov/engine.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,19 @@ def summary(self, stream):
140140

141141
# Output coverage section header.
142142
if len(self.node_descs) == 1:
143-
self.sep(stream, '-', 'coverage: %s' % ''.join(self.node_descs))
143+
self.sep(stream, '-', f"coverage: {''.join(self.node_descs)}")
144144
else:
145145
self.sep(stream, '-', 'coverage')
146146
for node_desc in sorted(self.node_descs):
147-
self.sep(stream, ' ', '%s' % node_desc)
147+
self.sep(stream, ' ', f'{node_desc}')
148148

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

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

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

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

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

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

218218
return total
219219

‎src/pytest_cov/plugin.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ def pytest_runtestloop(self, session):
306306
try:
307307
self.cov_total = self.cov_controller.summary(self.cov_report)
308308
except CoverageException as exc:
309-
message = 'Failed to generate report: %s\n' % exc
309+
message = f'Failed to generate report: {exc}\n'
310310
session.config.pluginmanager.getplugin("terminalreporter").write(
311-
'WARNING: %s\n' % message, red=True, bold=True)
311+
f'WARNING: {message}\n', red=True, bold=True)
312312
warnings.warn(CovReportWarning(message))
313313
self.cov_total = 0
314314
assert self.cov_total is not None, 'Test coverage should never be `None`'
@@ -320,7 +320,7 @@ def pytest_terminal_summary(self, terminalreporter):
320320
if self._disabled:
321321
if self.options.no_cov_should_warn:
322322
message = 'Coverage disabled via --no-cov switch!'
323-
terminalreporter.write('WARNING: %s\n' % message, red=True, bold=True)
323+
terminalreporter.write(f'WARNING: {message}\n', red=True, bold=True)
324324
warnings.warn(CovDisabledWarning(message))
325325
return
326326
if self.cov_controller is None:

‎tests/test_pytest_cov.py

+136-136
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.