Skip to content

Commit

Permalink
Add ruff per-file-ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Mar 20, 2023
1 parent d5a6605 commit 7c21db2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 24 deletions.
27 changes: 21 additions & 6 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@ exclude = [
"dist",
]
ignore = [
"D", # pydocstyle
"ANN", # flake8-annotations
"ARG", # flake8-unused-arguments
"BLE", # flake8-blind-except
"C90", # mccabe
"COM", # flake8-comma
"D", # pydocstyle
"EM", # flake8-errmsg
"FBT", # flake8-boolean-trap
"INP", # flake8-no-pep420
"PLR", # Pylint Refactor
"PLR0133", # Pylint Refactor
"PLR2004",
"PLW", # Pylint Warning
"PTH", # flake8-use-pathlib
"Q", # flake8-quotes
"RET", # flake8-return
"S101", # flake8-bandit assert
"S102", # flake8-bandit exec
"S110", # flake8-bandit try-except-pass
"SIM102", # flake8-simplify collapsible-if
"SIM105", # flake8-simplify use-contextlib-suppress
"SLF", # flake8-self
"T20", # flake8-print
"S101", # flake8-bandit assert
"S102", # flake8-bandit exec
"S110", # flake8-bandit try-except-pass
"TRY", # tryceratops
]
line-length = 140
Expand All @@ -38,3 +40,16 @@ target-version = "py37"
force-single-line = true
forced-separate = ["test_pytest_cov"]
known-first-party = ["pytest_cov"]

[mccabe]
max-complexity = 12

[per-file-ignores]
"ci/bootstrap.py" = ["S701"]
"docs/conf.py" = ["A001"]
"src/pytest_cov/plugin.py" = ["B904", "PT004"]
"tests/test_pytest_cov.py" = ["N801", "PT004", "RSE102", "SIM117"]

[pylint]
max-args = 8
max-branches = 13
2 changes: 1 addition & 1 deletion examples/adhoc-layout/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

def test_add():
assert example.add(1, 1) == 2
assert not example.add(0, 1) == 2
assert example.add(0, 1) != 2
2 changes: 1 addition & 1 deletion examples/src-layout/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

def test_add():
assert example.add(1, 1) == 2
assert not example.add(0, 1) == 2
assert example.add(0, 1) != 2
7 changes: 2 additions & 5 deletions src/pytest_cov/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ def init():
import coverage

# Determine all source roots.
if cov_source in os.pathsep:
cov_source = None
else:
cov_source = cov_source.split(os.pathsep)
cov_source = None if cov_source in os.pathsep else cov_source.split(os.pathsep)
if cov_config == os.pathsep:
cov_config = True

Expand Down Expand Up @@ -108,7 +105,7 @@ def _signal_cleanup_handler(signum, frame):
elif signum == signal.SIGTERM:
os._exit(128 + signum)
elif signum == signal.SIGINT:
raise KeyboardInterrupt()
raise KeyboardInterrupt


def cleanup_on_signal(signum):
Expand Down
2 changes: 0 additions & 2 deletions src/pytest_cov/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,5 +412,3 @@ def finish(self):

def summary(self, stream):
"""Only the master reports so do nothing."""

pass
9 changes: 4 additions & 5 deletions src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def validate_report(arg):
all_choices = term_choices + file_choices
values = arg.split(":", 1)
report_type = values[0]
if report_type not in all_choices + ['']:
if report_type not in [*all_choices, '']:
msg = f'invalid choice: "{arg}" (choose from "{all_choices}")'
raise argparse.ArgumentTypeError(msg)

Expand Down Expand Up @@ -247,7 +247,7 @@ def pytest_sessionstart(self, session):
self.pid = os.getpid()
if self._is_worker(session):
nodeid = (
session.config.workerinput.get('workerid', getattr(session, 'nodeid'))
session.config.workerinput.get('workerid', session.nodeid)
)
self.start(engine.DistWorker, session.config, nodeid)
elif not self._started:
Expand Down Expand Up @@ -389,13 +389,12 @@ def switch_context(self, item, when):
os.environ['COV_CORE_CONTEXT'] = context


@pytest.fixture
@pytest.fixture()
def no_cover():
"""A pytest fixture to disable coverage."""
pass


@pytest.fixture
@pytest.fixture()
def cov(request):
"""A pytest fixture to provide access to the underlying coverage object."""

Expand Down
8 changes: 4 additions & 4 deletions tests/contextful.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_04(self):
assert self.items[0] == "hello" # r4


@pytest.fixture
@pytest.fixture()
def some_data():
return [1, 2, 3] # s5 s6

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


@pytest.fixture
@pytest.fixture()
def more_data(some_data):
return [2*x for x in some_data] # s6

Expand Down Expand Up @@ -83,15 +83,15 @@ def test_10():
assert 1 == 1 # r10


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


@pytest.mark.parametrize("x, ans", [
@pytest.mark.parametrize(("x", "ans"), [
(1, 101),
(2, 202),
], ids=['one', 'two'])
Expand Down

0 comments on commit 7c21db2

Please sign in to comment.