Skip to content

Commit 9dddf0a

Browse files
committed
Update some ci config, reformat and apply some lint fixes.
1 parent aa687ea commit 9dddf0a

File tree

4 files changed

+47
-59
lines changed

4 files changed

+47
-59
lines changed

ci/bootstrap.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ def exec_in_env():
2020
else:
2121
bin_path = env_path / 'bin'
2222
if not env_path.exists():
23-
import subprocess
24-
2523
print(f'Making bootstrap env in: {env_path} ...')
2624
try:
2725
check_call([sys.executable, '-m', 'venv', env_path])
@@ -59,7 +57,7 @@ def main():
5957
# This uses sys.executable the same way that the call in
6058
# cookiecutter-pylibrary/hooks/post_gen_project.py
6159
# invokes this bootstrap.py itself.
62-
for line in subprocess.check_output([sys.executable, '-m', 'tox', '--listenvs'], text=True).splitlines()
60+
for line in subprocess.check_output([sys.executable, '-m', 'tox', '--listenvs'], universal_newlines=True).splitlines()
6361
]
6462
tox_environments = [line for line in tox_environments if line.startswith('py')]
6563
for template in templates_path.rglob('*'):

ci/requirements.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
virtualenv>=16.6.0
2-
pip>=19.1.1
3-
setuptools>=18.0.1
4-
tox
5-
twine
1+
pip>=25
2+
setuptools>=80
3+
tox>=4
4+
virtualenv>=20.34

pyproject.toml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,18 @@ dependencies = [
5252

5353
[project.optional-dependencies]
5454
testing = [
55-
"fields",
56-
"hunter",
5755
"process-tests",
5856
"pytest-xdist",
59-
"six",
6057
"virtualenv",
6158
]
6259

6360
[project.entry-points.pytest11]
6461
pytest_cov = "pytest_cov.plugin"
6562

6663
[project.urls]
67-
Changelog = "https://pytest-cov.readthedocs.io/en/latest/changelog.html"
68-
Documentation = "https://pytest-cov.readthedocs.io/"
69-
Homepage = "https://github.com/pytest-dev/pytest-cov"
64+
"Sources" = "https://github.com/pytest-dev/pytest-cov"
65+
"Documentation" = "https://pytest-cov.readthedocs.io/"
66+
"Changelog" = "https://pytest-cov.readthedocs.io/en/latest/changelog.html"
7067
"Issue Tracker" = "https://github.com/pytest-dev/pytest-cov/issues"
7168

7269
[tool.hatch.metadata.hooks.fancy-pypi-readme]
@@ -87,30 +84,31 @@ target-version = "py39"
8784

8885
[tool.ruff.lint]
8986
ignore = [
90-
"RUF001", # ruff-specific rules ambiguous-unicode-character-string
91-
"S101", # flake8-bandit assert
92-
"S308", # flake8-bandit suspicious-mark-safe-usage
93-
"E501", # pycodestyle line-too-long
87+
"PLC0415", # `import` should be at the top-level of a file
88+
"RUF001", # ruff-specific rules ambiguous-unicode-character-string
89+
"S101", # flake8-bandit assert
90+
"S308", # flake8-bandit suspicious-mark-safe-usage
91+
"E501", # pycodestyle line-too-long
9492
]
9593
select = [
96-
"B", # flake8-bugbear
97-
"C4", # flake8-comprehensions
94+
"B", # flake8-bugbear
95+
"C4", # flake8-comprehensions
9896
"DTZ", # flake8-datetimez
99-
"E", # pycodestyle errors
97+
"E", # pycodestyle errors
10098
"EXE", # flake8-executable
101-
"F", # pyflakes
102-
"I", # isort
99+
"F", # pyflakes
100+
"I", # isort
103101
"INT", # flake8-gettext
104102
"PIE", # flake8-pie
105103
"PLC", # pylint convention
106104
"PLE", # pylint errors
107-
"PT", # flake8-pytest-style
105+
"PT", # flake8-pytest-style
108106
"PTH", # flake8-use-pathlib
109107
"RSE", # flake8-raise
110108
"RUF", # ruff-specific rules
111-
"S", # flake8-bandit
112-
"UP", # pyupgrade
113-
"W", # pycodestyle warnings
109+
"S", # flake8-bandit
110+
"UP", # pyupgrade
111+
"W", # pycodestyle warnings
114112
]
115113

116114
[tool.ruff.lint.flake8-pytest-style]
@@ -123,4 +121,3 @@ force-single-line = true
123121

124122
[tool.ruff.format]
125123
quote-style = "single"
126-

tests/test_pytest_cov.py

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
# ruff: noqa
21
import collections
32
import glob
43
import os
54
import platform
65
import re
7-
import subprocess
86
import sys
9-
from io import StringIO
107
from itertools import chain
8+
from pathlib import Path
9+
from types import SimpleNamespace
1110

1211
import coverage
13-
import py
1412
import pytest
15-
import virtualenv
16-
import xdist
17-
from fields import Namespace
1813
from process_tests import TestProcess as _TestProcess
1914
from process_tests import dump_on_error
2015
from process_tests import wait_for_strings
2116

2217
import pytest_cov.plugin
2318

24-
coverage, platform # required for skipif mark on test_cov_min_from_coveragerc
19+
# required for skipif mark on test_cov_min_from_coveragerc
20+
coverage, platform # noqa: B018
2521

2622
max_worker_restart_0 = '--max-worker-restart=0'
2723

@@ -168,7 +164,7 @@ def test_foo(cov):
168164
def adjust_sys_path():
169165
"""Adjust PYTHONPATH during tests to make "helper" importable in SCRIPT."""
170166
orig_path = os.environ.get('PYTHONPATH', None)
171-
new_path = os.path.dirname(__file__)
167+
new_path = str(Path(__file__).parent)
172168
if orig_path is not None:
173169
new_path = os.pathsep.join([new_path, orig_path])
174170
os.environ['PYTHONPATH'] = new_path
@@ -191,7 +187,7 @@ def adjust_sys_path():
191187
ids=['branch2x', 'branch1c', 'branch1a', 'nobranch'],
192188
)
193189
def prop(request):
194-
return Namespace(
190+
return SimpleNamespace(
195191
code=SCRIPT,
196192
code2=SCRIPT2,
197193
conf=request.param[0],
@@ -348,7 +344,7 @@ def test_xml_output_dir(testdir):
348344
def test_json_output_dir(testdir):
349345
script = testdir.makepyfile(SCRIPT)
350346

351-
result = testdir.runpytest('-v', '--cov=%s' % script.dirpath(), '--cov-report=json:' + JSON_REPORT_NAME, script)
347+
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', '--cov-report=json:' + JSON_REPORT_NAME, script)
352348

353349
result.stdout.fnmatch_lines(
354350
[
@@ -364,7 +360,7 @@ def test_json_output_dir(testdir):
364360
def test_markdown_output_dir(testdir):
365361
script = testdir.makepyfile(SCRIPT)
366362

367-
result = testdir.runpytest('-v', '--cov=%s' % script.dirpath(), '--cov-report=markdown:' + MARKDOWN_REPORT_NAME, script)
363+
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', '--cov-report=markdown:' + MARKDOWN_REPORT_NAME, script)
368364

369365
result.stdout.fnmatch_lines(
370366
[
@@ -380,7 +376,7 @@ def test_markdown_output_dir(testdir):
380376
def test_markdown_append_output_dir(testdir):
381377
script = testdir.makepyfile(SCRIPT)
382378

383-
result = testdir.runpytest('-v', '--cov=%s' % script.dirpath(), '--cov-report=markdown-append:' + MARKDOWN_APPEND_REPORT_NAME, script)
379+
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', '--cov-report=markdown-append:' + MARKDOWN_APPEND_REPORT_NAME, script)
384380

385381
result.stdout.fnmatch_lines(
386382
[
@@ -398,7 +394,7 @@ def test_markdown_and_markdown_append_work_together(testdir):
398394

399395
result = testdir.runpytest(
400396
'-v',
401-
'--cov=%s' % script.dirpath(),
397+
f'--cov={script.dirpath()}',
402398
'--cov-report=markdown:' + MARKDOWN_REPORT_NAME,
403399
'--cov-report=markdown-append:' + MARKDOWN_APPEND_REPORT_NAME,
404400
script,
@@ -421,7 +417,7 @@ def test_markdown_and_markdown_append_pointing_to_same_file_throws_error(testdir
421417

422418
result = testdir.runpytest(
423419
'-v',
424-
'--cov=%s' % script.dirpath(),
420+
f'--cov={script.dirpath()}',
425421
'--cov-report=markdown:' + MARKDOWN_REPORT_NAME,
426422
'--cov-report=markdown-append:' + MARKDOWN_REPORT_NAME,
427423
script,
@@ -467,7 +463,7 @@ def test_term_missing_output_dir(testdir):
467463

468464
result.stderr.fnmatch_lines(
469465
[
470-
'*argument --cov-report: output specifier not supported for: "term-missing:%s"*' % DEST_DIR,
466+
f'*argument --cov-report: output specifier not supported for: "term-missing:{DEST_DIR}"*',
471467
]
472468
)
473469
assert result.ret != 0
@@ -754,7 +750,7 @@ def test_add_task(celery_worker):
754750
result.stdout.fnmatch_lines(
755751
[
756752
'*_ coverage: platform *, python * _*',
757-
f'small_celery* 100%*',
753+
'small_celery* 100%*',
758754
]
759755
)
760756
assert result.ret == 0
@@ -1337,7 +1333,7 @@ def test_run():
13371333
'-v', '--assert=plain', f'--cov={script.dirpath()}', '--cov-report=term-missing', '--cov-report=html', script
13381334
)
13391335

1340-
result.stdout.fnmatch_lines(['*_ coverage: platform *, python * _*', f'test_cleanup_on_sigterm* 88% * 18-19', '*1 passed*'])
1336+
result.stdout.fnmatch_lines(['*_ coverage: platform *, python * _*', 'test_cleanup_on_sigterm* 88% * 18-19', '*1 passed*'])
13411337
assert result.ret == 0
13421338

13431339

@@ -1644,7 +1640,7 @@ def test_dist_bare_cov(testdir):
16441640

16451641
def test_not_started_plugin_does_not_fail(testdir):
16461642
class ns:
1647-
cov_source = [True]
1643+
cov_source = (True,)
16481644
cov_report = ''
16491645

16501646
plugin = pytest_cov.plugin.CovPlugin(ns, None, start=False)
@@ -1692,14 +1688,13 @@ def test_external_data_file(testdir):
16921688
testdir.tmpdir.join('.coveragerc').write(
16931689
"""
16941690
[run]
1695-
data_file = %s
1696-
"""
1697-
% testdir.tmpdir.join('some/special/place/coverage-data').ensure()
1691+
data_file = {}
1692+
""".format(testdir.tmpdir.join('some/special/place/coverage-data').ensure())
16981693
)
16991694

17001695
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script)
17011696
assert result.ret == 0
1702-
assert glob.glob(str(testdir.tmpdir.join('some/special/place/coverage-data*')))
1697+
assert glob.glob(str(testdir.tmpdir.join('some/special/place/coverage-data*'))) # noqa: PTH207
17031698

17041699

17051700
@pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')
@@ -1709,14 +1704,13 @@ def test_external_data_file_xdist(testdir):
17091704
"""
17101705
[run]
17111706
parallel = true
1712-
data_file = %s
1713-
"""
1714-
% testdir.tmpdir.join('some/special/place/coverage-data').ensure()
1707+
data_file = {}
1708+
""".format(testdir.tmpdir.join('some/special/place/coverage-data').ensure())
17151709
)
17161710

17171711
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', '-n', '1', max_worker_restart_0, script)
17181712
assert result.ret == 0
1719-
assert glob.glob(str(testdir.tmpdir.join('some/special/place/coverage-data*')))
1713+
assert glob.glob(str(testdir.tmpdir.join('some/special/place/coverage-data*'))) # noqa: PTH207
17201714

17211715

17221716
@pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')
@@ -1743,7 +1737,7 @@ def test_external_data_file_negative(testdir):
17431737

17441738
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script)
17451739
assert result.ret == 0
1746-
assert glob.glob(str(testdir.tmpdir.join('.coverage*')))
1740+
assert glob.glob(str(testdir.tmpdir.join('.coverage*'))) # noqa: PTH207
17471741

17481742

17491743
@xdist_params
@@ -1851,7 +1845,7 @@ def test_do_not_append_coverage(pytester, testdir, opts, prop):
18511845

18521846
@pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')
18531847
def test_append_coverage_subprocess(testdir):
1854-
testdir.makepyprojecttoml(f"""
1848+
testdir.makepyprojecttoml("""
18551849
[tool.coverage.run]
18561850
patch = ["subprocess"]
18571851
""")
@@ -1965,7 +1959,7 @@ def find_labels(text, pattern):
19651959

19661960
@xdist_params
19671961
def test_contexts(pytester, testdir, opts):
1968-
with open(os.path.join(os.path.dirname(__file__), 'contextful.py')) as f:
1962+
with Path(__file__).parent.joinpath('contextful.py').open() as f:
19691963
contextful_tests = f.read()
19701964
script = testdir.makepyfile(contextful_tests)
19711965
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', '--cov-context=test', script, *opts.split())
@@ -1982,7 +1976,7 @@ def test_contexts(pytester, testdir, opts):
19821976
measured = data.measured_files()
19831977
assert len(measured) == 1
19841978
test_context_path = next(iter(measured))
1985-
assert test_context_path.lower() == os.path.abspath('test_contexts.py').lower()
1979+
assert test_context_path.lower() == os.path.abspath('test_contexts.py').lower() # noqa: PTH100
19861980

19871981
line_data = find_labels(contextful_tests, r'[crst]\d+(?:-\d+)?')
19881982
for context, label in EXPECTED_CONTEXTS.items():

0 commit comments

Comments
 (0)