Skip to content

Commit 430f0c8

Browse files
committed
Make changes requested in code review
1 parent 4200898 commit 430f0c8

File tree

10 files changed

+55
-42
lines changed

10 files changed

+55
-42
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ repos:
1414
rev: v0.0.253
1515
hooks:
1616
- id: ruff
17-
# args: [--fix, --exit-non-zero-on-fix]
17+
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

.ruff.toml

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,33 @@ exclude = [
66
"ci/templates",
77
"dist",
88
]
9-
line-length = 140
10-
select = [
11-
"E",
12-
"F",
13-
"I",
14-
"PLC",
15-
"PLE",
16-
"UP",
17-
"W",
9+
ignore = [
10+
"ANN", # flake8-annotations
11+
"ARG", # flake8-unused-arguments
12+
"BLE", # flake8-blind-except
13+
"COM", # flake8-comma
14+
"D", # pydocstyle
15+
"EM", # flake8-errmsg
16+
"FBT", # flake8-boolean-trap
17+
"INP", # flake8-no-pep420
18+
"PLR0133", # Pylint Refactor
19+
"PLR2004", # Pylint Refactor
20+
"PLW", # Pylint Warning
21+
"PTH", # flake8-use-pathlib
22+
"Q", # flake8-quotes
23+
"RET", # flake8-return
24+
"RUF100", # Ruff-internal
25+
"S101", # flake8-bandit assert
26+
"S102", # flake8-bandit exec
27+
"S110", # flake8-bandit try-except-pass
28+
"SIM102", # flake8-simplify collapsible-if
29+
"SIM105", # flake8-simplify use-contextlib-suppress
30+
"SLF", # flake8-self
31+
"T20", # flake8-print
32+
"TRY", # tryceratops
1833
]
34+
line-length = 140
35+
select = ["ALL"]
1936
target-version = "py37"
2037

2138
# [tool.ruff.isort] # <- TODO Uncomment when migrating to pyproject.toml
@@ -24,3 +41,17 @@ target-version = "py37"
2441
force-single-line = true
2542
forced-separate = ["test_pytest_cov"]
2643
known-first-party = ["pytest_cov"]
44+
45+
[mccabe]
46+
max-complexity = 12
47+
48+
[per-file-ignores]
49+
"ci/bootstrap.py" = ["S701"]
50+
"docs/conf.py" = ["A001"]
51+
"src/pytest_cov/plugin.py" = ["B904", "PT004"]
52+
"setup.py" = ["SIM117"]
53+
"tests/test_pytest_cov.py" = ["N801", "PT004", "RSE102", "SIM117"]
54+
55+
[pylint]
56+
max-args = 8
57+
max-branches = 13

examples/adhoc-layout/tests/test_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
def test_add():
55
assert example.add(1, 1) == 2
6-
assert not example.add(0, 1) == 2
6+
assert example.add(0, 1) != 2

examples/src-layout/tests/test_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
def test_add():
55
assert example.add(1, 1) == 2
6-
assert not example.add(0, 1) == 2
6+
assert example.add(0, 1) != 2

setup.cfg

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
[flake8]
2-
max-line-length = 140
3-
exclude = .tox,.eggs,ci/templates,build,dist
4-
51
[tool:pytest]
62
testpaths = tests
73
python_files = test_*.py
84
addopts =
95
-ra
106
--strict
117
-p pytester
12-
13-
[tool:isort]
14-
force_single_line = True
15-
line_length = 120
16-
known_first_party = pytest_cov
17-
default_section = THIRDPARTY
18-
forced_separate = test_pytest_cov
19-
skip = .tox,.eggs,ci/templates,build,dist

src/pytest_cov/embed.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ def init():
3838
import coverage
3939

4040
# Determine all source roots.
41-
if cov_source in os.pathsep:
42-
cov_source = None
43-
else:
44-
cov_source = cov_source.split(os.pathsep)
41+
cov_source = None if cov_source in os.pathsep else cov_source.split(os.pathsep)
4542
if cov_config == os.pathsep:
4643
cov_config = True
4744

@@ -108,7 +105,7 @@ def _signal_cleanup_handler(signum, frame):
108105
elif signum == signal.SIGTERM:
109106
os._exit(128 + signum)
110107
elif signum == signal.SIGINT:
111-
raise KeyboardInterrupt()
108+
raise KeyboardInterrupt
112109

113110

114111
def cleanup_on_signal(signum):

src/pytest_cov/engine.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,5 +412,3 @@ def finish(self):
412412

413413
def summary(self, stream):
414414
"""Only the master reports so do nothing."""
415-
416-
pass

src/pytest_cov/plugin.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def validate_report(arg):
3535
all_choices = term_choices + file_choices
3636
values = arg.split(":", 1)
3737
report_type = values[0]
38-
if report_type not in all_choices + ['']:
38+
if report_type not in [*all_choices, '']:
3939
msg = f'invalid choice: "{arg}" (choose from "{all_choices}")'
4040
raise argparse.ArgumentTypeError(msg)
4141

@@ -247,7 +247,7 @@ def pytest_sessionstart(self, session):
247247
self.pid = os.getpid()
248248
if self._is_worker(session):
249249
nodeid = (
250-
session.config.workerinput.get('workerid', getattr(session, 'nodeid'))
250+
session.config.workerinput.get('workerid', session.nodeid)
251251
)
252252
self.start(engine.DistWorker, session.config, nodeid)
253253
elif not self._started:
@@ -389,13 +389,12 @@ def switch_context(self, item, when):
389389
os.environ['COV_CORE_CONTEXT'] = context
390390

391391

392-
@pytest.fixture
392+
@pytest.fixture()
393393
def no_cover():
394394
"""A pytest fixture to disable coverage."""
395-
pass
396395

397396

398-
@pytest.fixture
397+
@pytest.fixture()
399398
def cov(request):
400399
"""A pytest fixture to provide access to the underlying coverage object."""
401400

tests/contextful.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_04(self):
3939
assert self.items[0] == "hello" # r4
4040

4141

42-
@pytest.fixture
42+
@pytest.fixture()
4343
def some_data():
4444
return [1, 2, 3] # s5 s6
4545

@@ -48,7 +48,7 @@ def test_05(some_data):
4848
assert len(some_data) == 3 # r5
4949

5050

51-
@pytest.fixture
51+
@pytest.fixture()
5252
def more_data(some_data):
5353
return [2*x for x in some_data] # s6
5454

@@ -83,15 +83,15 @@ def test_10():
8383
assert 1 == 1 # r10
8484

8585

86-
@pytest.mark.parametrize("x, ans", [
86+
@pytest.mark.parametrize(("x", "ans"), [
8787
(1, 101),
8888
(2, 202),
8989
])
9090
def test_11(x, ans):
9191
assert 100 * x + x == ans # r11-1 r11-2
9292

9393

94-
@pytest.mark.parametrize("x, ans", [
94+
@pytest.mark.parametrize(("x", "ans"), [
9595
(1, 101),
9696
(2, 202),
9797
], ids=['one', 'two'])

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ deps =
9393
check-manifest
9494
colorama # TODO Remove when isort > v6.0.0b2 is released.
9595
docutils
96-
flake8
9796
isort
9897
pygments
9998
readme-renderer
99+
ruff
100100
skip_install = true
101101
usedevelop = false
102102
commands =
103103
python setup.py check --strict --metadata --restructuredtext
104104
check-manifest {toxinidir}
105-
flake8 src tests setup.py
105+
ruff .
106106
isort --check-only --diff src tests setup.py

0 commit comments

Comments
 (0)