From 7c21db24ab84c5a97063a738053697b18f668069 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 20 Mar 2023 18:24:03 +0100 Subject: [PATCH] Add ruff per-file-ignores --- .ruff.toml | 27 ++++++++++++++++----- examples/adhoc-layout/tests/test_example.py | 2 +- examples/src-layout/tests/test_example.py | 2 +- src/pytest_cov/embed.py | 7 ++---- src/pytest_cov/engine.py | 2 -- src/pytest_cov/plugin.py | 9 +++---- tests/contextful.py | 8 +++--- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/.ruff.toml b/.ruff.toml index 87f624d5..826c1311 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -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 @@ -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 diff --git a/examples/adhoc-layout/tests/test_example.py b/examples/adhoc-layout/tests/test_example.py index f4948e66..8cf207de 100644 --- a/examples/adhoc-layout/tests/test_example.py +++ b/examples/adhoc-layout/tests/test_example.py @@ -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 diff --git a/examples/src-layout/tests/test_example.py b/examples/src-layout/tests/test_example.py index f4948e66..8cf207de 100644 --- a/examples/src-layout/tests/test_example.py +++ b/examples/src-layout/tests/test_example.py @@ -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 diff --git a/src/pytest_cov/embed.py b/src/pytest_cov/embed.py index f8a2749f..be50a50b 100644 --- a/src/pytest_cov/embed.py +++ b/src/pytest_cov/embed.py @@ -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 @@ -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): diff --git a/src/pytest_cov/engine.py b/src/pytest_cov/engine.py index 27e1a090..91e32169 100644 --- a/src/pytest_cov/engine.py +++ b/src/pytest_cov/engine.py @@ -412,5 +412,3 @@ def finish(self): def summary(self, stream): """Only the master reports so do nothing.""" - - pass diff --git a/src/pytest_cov/plugin.py b/src/pytest_cov/plugin.py index dd7b8c4e..4dfab1a0 100644 --- a/src/pytest_cov/plugin.py +++ b/src/pytest_cov/plugin.py @@ -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) @@ -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: @@ -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.""" diff --git a/tests/contextful.py b/tests/contextful.py index 3527e499..7edb87c0 100644 --- a/tests/contextful.py +++ b/tests/contextful.py @@ -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 @@ -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 @@ -83,7 +83,7 @@ def test_10(): assert 1 == 1 # r10 -@pytest.mark.parametrize("x, ans", [ +@pytest.mark.parametrize(("x", "ans"), [ (1, 101), (2, 202), ]) @@ -91,7 +91,7 @@ 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'])