From 76fb2a6cb2c4a4a788a5b62710848daf9c8fb7ce Mon Sep 17 00:00:00 2001 From: Mark Mayo Date: Sun, 11 Dec 2022 23:51:58 +1300 Subject: [PATCH] introduced f-strings converted to more modern f-strings --- setup.py | 3 +- src/pytest_cov/engine.py | 14 +- src/pytest_cov/plugin.py | 6 +- tests/test_pytest_cov.py | 272 +++++++++++++++++++-------------------- 4 files changed, 147 insertions(+), 148 deletions(-) diff --git a/setup.py b/setup.py index 7c3eaad1..e2cafde7 100755 --- a/setup.py +++ b/setup.py @@ -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})" ) diff --git a/src/pytest_cov/engine.py b/src/pytest_cov/engine.py index f045aed5..97d4d017 100644 --- a/src/pytest_cov/engine.py +++ b/src/pytest_cov/engine.py @@ -140,11 +140,11 @@ 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: @@ -152,7 +152,7 @@ def summary(self, stream): 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']): @@ -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') @@ -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: @@ -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 diff --git a/src/pytest_cov/plugin.py b/src/pytest_cov/plugin.py index 036c6375..2a1544a6 100644 --- a/src/pytest_cov/plugin.py +++ b/src/pytest_cov/plugin.py @@ -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`' @@ -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: diff --git a/tests/test_pytest_cov.py b/tests/test_pytest_cov.py index 5e3d0a3f..dde64f8f 100644 --- a/tests/test_pytest_cov.py +++ b/tests/test_pytest_cov.py @@ -188,8 +188,8 @@ def prop(request): code=SCRIPT, code2=SCRIPT2, conf=request.param[0], - fullconf='[run]\n%s\n' % request.param[0], - prefixedfullconf='[coverage:run]\n%s\n' % request.param[0], + fullconf=f'[run]\n{request.param[0]}\n', + prefixedfullconf=f'[coverage:run]\n{request.param[0]}\n', args=request.param[1].split(), result=request.param[2], result2=request.param[3], @@ -201,14 +201,14 @@ def test_central(pytester, testdir, prop): testdir.tmpdir.join('.coveragerc').write(prop.fullconf) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script, *prop.args) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_central* %s *' % prop.result, + f'test_central* {prop.result} *', '*10 passed*' ]) assert result.ret == 0 @@ -218,7 +218,7 @@ def test_annotate(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=annotate', script) @@ -234,7 +234,7 @@ def test_annotate_output_dir(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=annotate:' + DEST_DIR, script) @@ -253,7 +253,7 @@ def test_html(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=html', script) @@ -272,7 +272,7 @@ def test_html_output_dir(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=html:' + DEST_DIR, script) @@ -291,7 +291,7 @@ def test_term_report_does_not_interact_with_html_output(testdir): script = testdir.makepyfile(test_funcarg=SCRIPT_FUNCARG) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing:skip-covered', '--cov-report=html:' + DEST_DIR, script) @@ -315,7 +315,7 @@ def test_html_configured_output_dir(testdir): directory = somewhere """) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=html', script) @@ -334,7 +334,7 @@ def test_xml_output_dir(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=xml:' + XML_REPORT_NAME, script) @@ -369,7 +369,7 @@ def test_lcov_output_dir(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=lcov:' + LCOV_REPORT_NAME, script) @@ -386,7 +386,7 @@ def test_lcov_output_dir(testdir): def test_lcov_not_supported(testdir): script = testdir.makepyfile("a = 1") result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=lcov', script, ) @@ -400,12 +400,12 @@ def test_term_output_dir(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term:' + DEST_DIR, script) result.stderr.fnmatch_lines([ - '*argument --cov-report: output specifier not supported for: "term:%s"*' % DEST_DIR, + f'*argument --cov-report: output specifier not supported for: "term:{DEST_DIR}"*', ]) assert result.ret != 0 @@ -414,7 +414,7 @@ def test_term_missing_output_dir(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing:' + DEST_DIR, script) @@ -429,7 +429,7 @@ def test_cov_min_100(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '--cov-fail-under=100', script) @@ -444,7 +444,7 @@ def test_cov_min_100_passes_if_collectonly(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '--cov-fail-under=100', '--collect-only', @@ -457,7 +457,7 @@ def test_cov_min_50(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=html', '--cov-report=xml', '--cov-fail-under=50', @@ -473,7 +473,7 @@ def test_cov_min_float_value(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '--cov-fail-under=88.88', script) @@ -487,7 +487,7 @@ def test_cov_min_float_value_not_reached(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '--cov-fail-under=88.89', script) @@ -501,7 +501,7 @@ def test_cov_min_no_report(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=', '--cov-fail-under=50', script) @@ -522,7 +522,7 @@ def test_central_nonspecific(pytester, testdir, prop): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_central_nonspecific* %s *' % prop.result, + f'test_central_nonspecific* {prop.result} *', '*10 passed*' ]) @@ -540,7 +540,7 @@ def test_cov_min_from_coveragerc(testdir): """) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) @@ -558,7 +558,7 @@ def test_central_coveragerc(pytester, testdir, prop): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_central_coveragerc* %s *' % prop.result, + f'test_central_coveragerc* {prop.result} *', '*10 passed*', ]) assert result.ret == 0 @@ -573,7 +573,7 @@ def test_central_with_path_aliasing(pytester, testdir, monkeypatch, opts, prop): script = testdir.makepyfile(''' from mod import * ''') - testdir.tmpdir.join('setup.cfg').write(""" + testdir.tmpdir.join('setup.cfg').write(f""" [coverage:paths] source = src @@ -581,8 +581,8 @@ def test_central_with_path_aliasing(pytester, testdir, monkeypatch, opts, prop): [coverage:run] source = mod parallel = true -%s -""" % prop.conf) +{prop.conf} +""") monkeypatch.setitem(os.environ, 'PYTHONPATH', os.pathsep.join([os.environ.get('PYTHONPATH', ''), 'aliased'])) result = testdir.runpytest('-v', '-s', @@ -592,7 +592,7 @@ def test_central_with_path_aliasing(pytester, testdir, monkeypatch, opts, prop): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'src[\\/]mod* %s *' % prop.result, + f'src[\\/]mod* {prop.result} *', '*10 passed*', ]) assert result.ret == 0 @@ -668,22 +668,22 @@ def test_subprocess_with_path_aliasing(pytester, testdir, monkeypatch): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'src[\\/]child_script* %s*' % CHILD_SCRIPT_RESULT, - 'src[\\/]parent_script* %s*' % PARENT_SCRIPT_RESULT, + f'src[\\/]child_script* {CHILD_SCRIPT_RESULT}*', + f'src[\\/]parent_script* {PARENT_SCRIPT_RESULT}*', ]) assert result.ret == 0 def test_show_missing_coveragerc(pytester, testdir, prop): script = testdir.makepyfile(prop.code) - testdir.tmpdir.join('.coveragerc').write(""" + testdir.tmpdir.join('.coveragerc').write(f""" [run] source = . -%s +{prop.conf} [report] show_missing = true -""" % prop.conf) +""") result = testdir.runpytest('-v', '--cov', @@ -693,7 +693,7 @@ def test_show_missing_coveragerc(pytester, testdir, prop): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', 'Name * Stmts * Miss * Cover * Missing', - 'test_show_missing_coveragerc* %s * 11*' % prop.result, + f'test_show_missing_coveragerc* {prop.result} * 11*', '*10 passed*', ]) @@ -708,7 +708,7 @@ def test_fail(): ''') result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '--no-cov-on-fail', script) @@ -724,7 +724,7 @@ def test_no_cov(pytester, testdir, monkeypatch): addopts=--no-cov """) result = testdir.runpytest('-vvv', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '-rw', script) @@ -742,7 +742,7 @@ def test_fail(p): ''') result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-fail-under=100', '--cov-report=html', script) @@ -762,13 +762,13 @@ def test_dist_combine_racecondition(testdir): @pytest.mark.parametrize("foo", range(1000)) def test_foo(foo): -""" + "\n".join(""" - if foo == %s: +""" + "\n".join(f""" + if foo == {i}: assert True -""" % i for i in range(1000))) +""" for i in range(1000))) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '-n', '5', '-s', script) @@ -788,7 +788,7 @@ def test_dist_collocated(pytester, testdir, prop): script = testdir.makepyfile(prop.code) testdir.tmpdir.join('.coveragerc').write(prop.fullconf) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '--dist=load', '--tx=2*popen', @@ -797,7 +797,7 @@ def test_dist_collocated(pytester, testdir, prop): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_dist_collocated* %s *' % prop.result, + f'test_dist_collocated* {prop.result} *', '*10 passed*' ]) assert result.ret == 0 @@ -808,29 +808,29 @@ def test_dist_not_collocated(pytester, testdir, prop): script = testdir.makepyfile(prop.code) dir1 = testdir.mkdir('dir1') dir2 = testdir.mkdir('dir2') - testdir.tmpdir.join('.coveragerc').write(''' + testdir.tmpdir.join('.coveragerc').write(f''' [run] -%s +{prop.conf} [paths] source = . dir1 - dir2''' % prop.conf) + dir2''') result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '--dist=load', - '--tx=popen//chdir=%s' % dir1, - '--tx=popen//chdir=%s' % dir2, - '--rsyncdir=%s' % script.basename, + f'--tx=popen//chdir={dir1}', + f'--tx=popen//chdir={dir2}', + f'--rsyncdir={script.basename}', '--rsyncdir=.coveragerc', max_worker_restart_0, '-s', script, *prop.args) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_dist_not_collocated* %s *' % prop.result, + f'test_dist_not_collocated* {prop.result} *', '*10 passed*' ]) assert result.ret == 0 @@ -841,30 +841,30 @@ def test_dist_not_collocated_coveragerc_source(pytester, testdir, prop): script = testdir.makepyfile(prop.code) dir1 = testdir.mkdir('dir1') dir2 = testdir.mkdir('dir2') - testdir.tmpdir.join('.coveragerc').write(''' + testdir.tmpdir.join('.coveragerc').write(f''' [run] -{} -source = {} +{prop.conf} +source = {script.dirpath()} [paths] source = . dir1 - dir2'''.format(prop.conf, script.dirpath())) + dir2''') result = testdir.runpytest('-v', '--cov', '--cov-report=term-missing', '--dist=load', - '--tx=popen//chdir=%s' % dir1, - '--tx=popen//chdir=%s' % dir2, - '--rsyncdir=%s' % script.basename, + f'--tx=popen//chdir={dir1}', + f'--tx=popen//chdir={dir2}', + f'--rsyncdir={script.basename}', '--rsyncdir=.coveragerc', max_worker_restart_0, '-s', script, *prop.args) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_dist_not_collocated* %s *' % prop.result, + f'test_dist_not_collocated* {prop.result} *', '*10 passed*' ]) assert result.ret == 0 @@ -876,14 +876,14 @@ def test_central_subprocess(testdir): parent_script = scripts.dirpath().join('parent_script.py') result = testdir.runpytest('-v', - '--cov=%s' % scripts.dirpath(), + f'--cov={scripts.dirpath()}', '--cov-report=term-missing', parent_script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'child_script* %s*' % CHILD_SCRIPT_RESULT, - 'parent_script* %s*' % PARENT_SCRIPT_RESULT, + f'child_script* {CHILD_SCRIPT_RESULT}*', + f'parent_script* {PARENT_SCRIPT_RESULT}*', ]) assert result.ret == 0 @@ -899,14 +899,14 @@ def test_central_subprocess_change_cwd(testdir): """) result = testdir.runpytest('-v', '-s', - '--cov=%s' % scripts.dirpath(), + f'--cov={scripts.dirpath()}', '--cov-config=coveragerc', '--cov-report=term-missing', parent_script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - '*child_script* %s*' % CHILD_SCRIPT_RESULT, + f'*child_script* {CHILD_SCRIPT_RESULT}*', '*parent_script* 100%*', ]) assert result.ret == 0 @@ -932,7 +932,7 @@ def test_central_subprocess_change_cwd_with_pythonpath(pytester, testdir, monkey result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - '*child_script* %s*' % CHILD_SCRIPT_RESULT, + f'*child_script* {CHILD_SCRIPT_RESULT}*', ]) assert result.ret == 0 @@ -950,7 +950,7 @@ def test_foo(): """) result = testdir.runpytest('-v', '--cov-config=coveragerc', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-branch', script) result.stdout.fnmatch_lines([ @@ -967,7 +967,7 @@ def test_dist_subprocess_collocated(testdir): parent_script = scripts.dirpath().join('parent_script.py') result = testdir.runpytest('-v', - '--cov=%s' % scripts.dirpath(), + f'--cov={scripts.dirpath()}', '--cov-report=term-missing', '--dist=load', '--tx=2*popen', @@ -976,8 +976,8 @@ def test_dist_subprocess_collocated(testdir): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'child_script* %s*' % CHILD_SCRIPT_RESULT, - 'parent_script* %s*' % PARENT_SCRIPT_RESULT, + f'child_script* {CHILD_SCRIPT_RESULT}*', + f'parent_script* {PARENT_SCRIPT_RESULT}*', ]) assert result.ret == 0 @@ -991,28 +991,28 @@ def test_dist_subprocess_not_collocated(pytester, testdir, tmpdir): dir1 = tmpdir.mkdir('dir1') dir2 = tmpdir.mkdir('dir2') - testdir.tmpdir.join('.coveragerc').write(''' + testdir.tmpdir.join('.coveragerc').write(f''' [paths] source = - %s + {scripts.dirpath()} */dir1 */dir2 -''' % scripts.dirpath()) +''') result = testdir.runpytest('-v', - '--cov=%s' % scripts.dirpath(), + f'--cov={scripts.dirpath()}', '--dist=load', - '--tx=popen//chdir=%s' % dir1, - '--tx=popen//chdir=%s' % dir2, - '--rsyncdir=%s' % child_script, - '--rsyncdir=%s' % parent_script, + f'--tx=popen//chdir={dir1}', + f'--tx=popen//chdir={dir2}', + f'--rsyncdir={child_script}', + f'--rsyncdir={parent_script}', '--rsyncdir=.coveragerc', max_worker_restart_0, parent_script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'child_script* %s*' % CHILD_SCRIPT_RESULT, - 'parent_script* %s*' % PARENT_SCRIPT_RESULT, + f'child_script* {CHILD_SCRIPT_RESULT}*', + f'parent_script* {PARENT_SCRIPT_RESULT}*', ]) assert result.ret == 0 @@ -1062,19 +1062,19 @@ def test_dist_missing_data(testdir): exe, '-mpip', 'install', - 'py==%s' % py.__version__, - 'pytest==%s' % pytest.__version__, - 'pytest_xdist==%s' % xdist.__version__ + f'py=={py.__version__}', + f'pytest=={pytest.__version__}', + f'pytest_xdist=={xdist.__version__}' ]) script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', '--assert=plain', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '--dist=load', - '--tx=popen//python=%s' % exe, + f'--tx=popen//python={exe}', max_worker_restart_0, str(script)) result.stdout.fnmatch_lines([ @@ -1086,7 +1086,7 @@ def test_funcarg(testdir): script = testdir.makepyfile(SCRIPT_FUNCARG) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) @@ -1144,7 +1144,7 @@ def test_run(): ''') result = testdir.runpytest('-vv', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) @@ -1190,13 +1190,13 @@ def test_run(): ''') result = testdir.runpytest('-vv', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_cleanup_on_sigterm* %s' % setup[1], + f'test_cleanup_on_sigterm* {setup[1]}', '*1 passed*' ]) assert result.ret == 0 @@ -1235,13 +1235,13 @@ def test_run(): result = testdir.runpytest('-vv', '--assert=plain', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_cleanup_on_sigterm* %s' % setup[1], + f'test_cleanup_on_sigterm* {setup[1]}', '*1 passed*' ]) assert result.ret == 0 @@ -1276,7 +1276,7 @@ def test_run(): result = testdir.runpytest('-vv', '--assert=plain', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) @@ -1320,7 +1320,7 @@ def test_run(): result = testdir.runpytest('-vv', '--assert=plain', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) @@ -1361,7 +1361,7 @@ def test_cover_conftest(testdir): testdir.makeconftest(CONFTEST) script = testdir.makepyfile(BASIC_TEST) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) assert result.ret == 0 @@ -1383,7 +1383,7 @@ def mock_run(*args, **kwargs): monkeypatch.setattr(testdir._pytester, 'run', mock_run) assert testdir._pytester.run is mock_run with testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--looponfail', script) as process: with dump_on_error(process.read): @@ -1400,7 +1400,7 @@ def test_cover_conftest_dist(testdir): testdir.makeconftest(CONFTEST) script = testdir.makepyfile(BASIC_TEST) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '--dist=load', '--tx=2*popen', @@ -1424,7 +1424,7 @@ def test_basic(): subprocess.check_call([sys.executable, '-c', 'from mod import func; func()']) ''') result = testdir.runpytest('-v', '-ra', '--strict', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) assert result.ret == 0 @@ -1443,7 +1443,7 @@ def test_basic(no_cover): subprocess.check_call([sys.executable, '-c', 'from mod import func; func()']) ''') result = testdir.runpytest('-v', '-ra', '--strict', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) assert result.ret == 0 @@ -1476,11 +1476,11 @@ def test_coveragerc(testdir): script = testdir.makepyfile(EXCLUDED_TEST) result = testdir.runpytest('-v', '--cov-config=coveragerc', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) assert result.ret == 0 - result.stdout.fnmatch_lines(['test_coveragerc* %s' % EXCLUDED_RESULT]) + result.stdout.fnmatch_lines([f'test_coveragerc* {EXCLUDED_RESULT}']) @pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"') @@ -1489,14 +1489,14 @@ def test_coveragerc_dist(testdir): script = testdir.makepyfile(EXCLUDED_TEST) result = testdir.runpytest('-v', '--cov-config=coveragerc', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', '-n', '2', max_worker_restart_0, script) assert result.ret == 0 result.stdout.fnmatch_lines( - ['test_coveragerc_dist* %s' % EXCLUDED_RESULT]) + [f'test_coveragerc_dist* {EXCLUDED_RESULT}']) SKIP_COVERED_COVERAGERC = ''' @@ -1525,8 +1525,8 @@ def test_skip_covered_cli(pytester, testdir, report_option): testdir.makefile('', coveragerc=SKIP_COVERED_COVERAGERC) script = testdir.makepyfile(SKIP_COVERED_TEST) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), - '--cov-report=%s' % report_option, + f'--cov={script.dirpath()}', + f'--cov-report={report_option}', script) assert result.ret == 0 result.stdout.fnmatch_lines([SKIP_COVERED_RESULT]) @@ -1537,7 +1537,7 @@ def test_skip_covered_coveragerc_config(testdir): script = testdir.makepyfile(SKIP_COVERED_TEST) result = testdir.runpytest('-v', '--cov-config=coveragerc', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', script) assert result.ret == 0 result.stdout.fnmatch_lines([SKIP_COVERED_RESULT]) @@ -1556,7 +1556,7 @@ def test_basic(): def test_clear_environ(testdir): script = testdir.makepyfile(CLEAR_ENVIRON_TEST) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=term-missing', script) assert result.ret == 0 @@ -1582,13 +1582,13 @@ def test_dist_boxed(testdir): result = testdir.runpytest('-v', '--assert=plain', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--boxed', script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_dist_boxed* %s*' % SCRIPT_SIMPLE_RESULT, + f'test_dist_boxed* {SCRIPT_SIMPLE_RESULT}*', '*1 passed*' ]) assert result.ret == 0 @@ -1607,7 +1607,7 @@ def test_dist_bare_cov(testdir): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_dist_bare_cov* %s*' % SCRIPT_SIMPLE_RESULT, + f'test_dist_bare_cov* {SCRIPT_SIMPLE_RESULT}*', '*1 passed*' ]) assert result.ret == 0 @@ -1627,7 +1627,7 @@ def test_default_output_setting(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', script) result.stdout.fnmatch_lines([ @@ -1640,7 +1640,7 @@ def test_disabled_output(testdir): script = testdir.makepyfile(SCRIPT) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-report=', script) @@ -1657,7 +1657,7 @@ def test_coverage_file(testdir): data_file_name = 'covdata' os.environ['COVERAGE_FILE'] = data_file_name try: - result = testdir.runpytest('-v', '--cov=%s' % script.dirpath(), + result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script) assert result.ret == 0 data_file = testdir.tmpdir.join(data_file_name) @@ -1674,7 +1674,7 @@ def test_external_data_file(testdir): """ % testdir.tmpdir.join('some/special/place/coverage-data').ensure()) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', script) assert result.ret == 0 assert glob.glob(str(testdir.tmpdir.join('some/special/place/coverage-data*'))) @@ -1690,7 +1690,7 @@ def test_external_data_file_xdist(testdir): """ % testdir.tmpdir.join('some/special/place/coverage-data').ensure()) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '-n', '1', max_worker_restart_0, script) @@ -1722,7 +1722,7 @@ def test_external_data_file_negative(testdir): testdir.tmpdir.join('.coveragerc').write("") result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', script) assert result.ret == 0 assert glob.glob(str(testdir.tmpdir.join('.coverage*'))) @@ -1733,21 +1733,21 @@ def test_append_coverage(pytester, testdir, opts, prop): script = testdir.makepyfile(test_1=prop.code) testdir.tmpdir.join('.coveragerc').write(prop.fullconf) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', script, *opts.split() + prop.args) result.stdout.fnmatch_lines([ - 'test_1* %s*' % prop.result, + f'test_1* {prop.result}*', ]) script2 = testdir.makepyfile(test_2=prop.code2) result = testdir.runpytest('-v', '--cov-append', - '--cov=%s' % script2.dirpath(), + f'--cov={script2.dirpath()}', script2, *opts.split() + prop.args) result.stdout.fnmatch_lines([ - 'test_1* %s*' % prop.result, - 'test_2* %s*' % prop.result2, + f'test_1* {prop.result}*', + f'test_2* {prop.result2}*', ]) @@ -1756,20 +1756,20 @@ def test_do_not_append_coverage(pytester, testdir, opts, prop): script = testdir.makepyfile(test_1=prop.code) testdir.tmpdir.join('.coveragerc').write(prop.fullconf) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', script, *opts.split()+prop.args) result.stdout.fnmatch_lines([ - 'test_1* %s*' % prop.result, + f'test_1* {prop.result}*', ]) script2 = testdir.makepyfile(test_2=prop.code2) result = testdir.runpytest('-v', - '--cov=%s' % script2.dirpath(), + f'--cov={script2.dirpath()}', script2, *opts.split()+prop.args) result.stdout.fnmatch_lines([ 'test_1* 0%', - 'test_2* %s*' % prop.result2, + f'test_2* {prop.result2}*', ]) @@ -1780,7 +1780,7 @@ def test_append_coverage_subprocess(testdir): parent_script = scripts.dirpath().join('parent_script.py') result = testdir.runpytest('-v', - '--cov=%s' % scripts.dirpath(), + f'--cov={scripts.dirpath()}', '--cov-append', '--cov-report=term-missing', '--dist=load', @@ -1790,8 +1790,8 @@ def test_append_coverage_subprocess(testdir): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'child_script* %s*' % CHILD_SCRIPT_RESULT, - 'parent_script* %s*' % PARENT_SCRIPT_RESULT, + f'child_script* {CHILD_SCRIPT_RESULT}*', + f'parent_script* {PARENT_SCRIPT_RESULT}*', ]) assert result.ret == 0 @@ -1825,12 +1825,12 @@ def test_double_cov(testdir): script = testdir.makepyfile(SCRIPT_SIMPLE) result = testdir.runpytest('-v', '--assert=plain', - '--cov', '--cov=%s' % script.dirpath(), + '--cov', f'--cov={script.dirpath()}', script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_double_cov* %s*' % SCRIPT_SIMPLE_RESULT, + f'test_double_cov* {SCRIPT_SIMPLE_RESULT}*', '*1 passed*' ]) assert result.ret == 0 @@ -1845,7 +1845,7 @@ def test_double_cov2(testdir): result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_double_cov2* %s*' % SCRIPT_SIMPLE_RESULT, + f'test_double_cov2* {SCRIPT_SIMPLE_RESULT}*', '*1 passed*' ]) assert result.ret == 0 @@ -1855,7 +1855,7 @@ def test_cov_reset(testdir): script = testdir.makepyfile(SCRIPT_SIMPLE) result = testdir.runpytest('-v', '--assert=plain', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-reset', script) @@ -1866,14 +1866,14 @@ def test_cov_reset_then_set(testdir): script = testdir.makepyfile(SCRIPT_SIMPLE) result = testdir.runpytest('-v', '--assert=plain', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-reset', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', script) result.stdout.fnmatch_lines([ '*- coverage: platform *, python * -*', - 'test_cov_reset_then_set* %s*' % SCRIPT_SIMPLE_RESULT, + f'test_cov_reset_then_set* {SCRIPT_SIMPLE_RESULT}*', '*1 passed*' ]) @@ -1943,7 +1943,7 @@ def test_contexts(pytester, testdir, opts): contextful_tests = f.read() script = testdir.makepyfile(contextful_tests) result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-context=test', script, *opts.split() @@ -1974,7 +1974,7 @@ def test_contexts(pytester, testdir, opts): def test_contexts_not_supported(testdir): script = testdir.makepyfile("a = 1") result = testdir.runpytest('-v', - '--cov=%s' % script.dirpath(), + f'--cov={script.dirpath()}', '--cov-context=test', script, )