Skip to content

Commit 97aadd7

Browse files
committed
Update some ci config, reformat and apply some lint fixes.
1 parent b5991fb commit 97aadd7

File tree

4 files changed

+45
-59
lines changed

4 files changed

+45
-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: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
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-
2519
max_worker_restart_0 = '--max-worker-restart=0'
2620

2721
SCRIPT = """
@@ -167,7 +161,7 @@ def test_foo(cov):
167161
def adjust_sys_path():
168162
"""Adjust PYTHONPATH during tests to make "helper" importable in SCRIPT."""
169163
orig_path = os.environ.get('PYTHONPATH', None)
170-
new_path = os.path.dirname(__file__)
164+
new_path = str(Path(__file__).parent)
171165
if orig_path is not None:
172166
new_path = os.pathsep.join([new_path, orig_path])
173167
os.environ['PYTHONPATH'] = new_path
@@ -190,7 +184,7 @@ def adjust_sys_path():
190184
ids=['branch2x', 'branch1c', 'branch1a', 'nobranch'],
191185
)
192186
def prop(request):
193-
return Namespace(
187+
return SimpleNamespace(
194188
code=SCRIPT,
195189
code2=SCRIPT2,
196190
conf=request.param[0],
@@ -347,7 +341,7 @@ def test_xml_output_dir(testdir):
347341
def test_json_output_dir(testdir):
348342
script = testdir.makepyfile(SCRIPT)
349343

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

352346
result.stdout.fnmatch_lines(
353347
[
@@ -363,7 +357,7 @@ def test_json_output_dir(testdir):
363357
def test_markdown_output_dir(testdir):
364358
script = testdir.makepyfile(SCRIPT)
365359

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

368362
result.stdout.fnmatch_lines(
369363
[
@@ -379,7 +373,7 @@ def test_markdown_output_dir(testdir):
379373
def test_markdown_append_output_dir(testdir):
380374
script = testdir.makepyfile(SCRIPT)
381375

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

384378
result.stdout.fnmatch_lines(
385379
[
@@ -397,7 +391,7 @@ def test_markdown_and_markdown_append_work_together(testdir):
397391

398392
result = testdir.runpytest(
399393
'-v',
400-
'--cov=%s' % script.dirpath(),
394+
f'--cov={script.dirpath()}',
401395
'--cov-report=markdown:' + MARKDOWN_REPORT_NAME,
402396
'--cov-report=markdown-append:' + MARKDOWN_APPEND_REPORT_NAME,
403397
script,
@@ -420,7 +414,7 @@ def test_markdown_and_markdown_append_pointing_to_same_file_throws_error(testdir
420414

421415
result = testdir.runpytest(
422416
'-v',
423-
'--cov=%s' % script.dirpath(),
417+
f'--cov={script.dirpath()}',
424418
'--cov-report=markdown:' + MARKDOWN_REPORT_NAME,
425419
'--cov-report=markdown-append:' + MARKDOWN_REPORT_NAME,
426420
script,
@@ -466,7 +460,7 @@ def test_term_missing_output_dir(testdir):
466460

467461
result.stderr.fnmatch_lines(
468462
[
469-
'*argument --cov-report: output specifier not supported for: "term-missing:%s"*' % DEST_DIR,
463+
f'*argument --cov-report: output specifier not supported for: "term-missing:{DEST_DIR}"*',
470464
]
471465
)
472466
assert result.ret != 0
@@ -755,7 +749,7 @@ def test_add_task(celery_worker):
755749
result.stdout.fnmatch_lines(
756750
[
757751
'*_ coverage: platform *, python * _*',
758-
f'small_celery* 100%*',
752+
'small_celery* 100%*',
759753
]
760754
)
761755
assert result.ret == 0
@@ -1353,7 +1347,7 @@ def test_run():
13531347
'-v', '--assert=plain', f'--cov={script.dirpath()}', '--cov-report=term-missing', '--cov-report=html', script
13541348
)
13551349

1356-
result.stdout.fnmatch_lines(['*_ coverage: platform *, python * _*', f'test_cleanup_on_sigterm* 88% * 18-19', '*1 passed*'])
1350+
result.stdout.fnmatch_lines(['*_ coverage: platform *, python * _*', 'test_cleanup_on_sigterm* 88% * 18-19', '*1 passed*'])
13571351
assert result.ret == 0
13581352

13591353

@@ -1649,7 +1643,7 @@ def test_dist_bare_cov(testdir):
16491643

16501644
def test_not_started_plugin_does_not_fail(testdir):
16511645
class ns:
1652-
cov_source = [True]
1646+
cov_source = (True,)
16531647
cov_report = ''
16541648

16551649
plugin = pytest_cov.plugin.CovPlugin(ns, None, start=False)
@@ -1697,14 +1691,13 @@ def test_external_data_file(testdir):
16971691
testdir.tmpdir.join('.coveragerc').write(
16981692
"""
16991693
[run]
1700-
data_file = %s
1701-
"""
1702-
% testdir.tmpdir.join('some/special/place/coverage-data').ensure()
1694+
data_file = {}
1695+
""".format(testdir.tmpdir.join('some/special/place/coverage-data').ensure())
17031696
)
17041697

17051698
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script)
17061699
assert result.ret == 0
1707-
assert glob.glob(str(testdir.tmpdir.join('some/special/place/coverage-data*')))
1700+
assert glob.glob(str(testdir.tmpdir.join('some/special/place/coverage-data*'))) # noqa: PTH207
17081701

17091702

17101703
@pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')
@@ -1714,14 +1707,13 @@ def test_external_data_file_xdist(testdir):
17141707
"""
17151708
[run]
17161709
parallel = true
1717-
data_file = %s
1718-
"""
1719-
% testdir.tmpdir.join('some/special/place/coverage-data').ensure()
1710+
data_file = {}
1711+
""".format(testdir.tmpdir.join('some/special/place/coverage-data').ensure())
17201712
)
17211713

17221714
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', '-n', '1', max_worker_restart_0, script)
17231715
assert result.ret == 0
1724-
assert glob.glob(str(testdir.tmpdir.join('some/special/place/coverage-data*')))
1716+
assert glob.glob(str(testdir.tmpdir.join('some/special/place/coverage-data*'))) # noqa: PTH207
17251717

17261718

17271719
@pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')
@@ -1748,7 +1740,7 @@ def test_external_data_file_negative(testdir):
17481740

17491741
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', script)
17501742
assert result.ret == 0
1751-
assert glob.glob(str(testdir.tmpdir.join('.coverage*')))
1743+
assert glob.glob(str(testdir.tmpdir.join('.coverage*'))) # noqa: PTH207
17521744

17531745

17541746
@xdist_params
@@ -1856,7 +1848,7 @@ def test_do_not_append_coverage(pytester, testdir, opts, prop):
18561848

18571849
@pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')
18581850
def test_append_coverage_subprocess(testdir):
1859-
testdir.makepyprojecttoml(f"""
1851+
testdir.makepyprojecttoml("""
18601852
[tool.coverage.run]
18611853
patch = ["subprocess"]
18621854
""")
@@ -1970,7 +1962,7 @@ def find_labels(text, pattern):
19701962

19711963
@xdist_params
19721964
def test_contexts(pytester, testdir, opts):
1973-
with open(os.path.join(os.path.dirname(__file__), 'contextful.py')) as f:
1965+
with Path(__file__).parent.joinpath('contextful.py').open() as f:
19741966
contextful_tests = f.read()
19751967
script = testdir.makepyfile(contextful_tests)
19761968
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', '--cov-context=test', script, *opts.split())
@@ -1987,7 +1979,7 @@ def test_contexts(pytester, testdir, opts):
19871979
measured = data.measured_files()
19881980
assert len(measured) == 1
19891981
test_context_path = next(iter(measured))
1990-
assert test_context_path.lower() == os.path.abspath('test_contexts.py').lower()
1982+
assert test_context_path.lower() == os.path.abspath('test_contexts.py').lower() # noqa: PTH100
19911983

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

0 commit comments

Comments
 (0)