From 90e4141cfd235b090ea868b153bd2fd10c73c04f Mon Sep 17 00:00:00 2001 From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> Date: Mon, 6 Nov 2023 17:26:15 +0200 Subject: [PATCH 1/3] Move `--cov-report=html` to `addopts` Non-`--cov` invocation is unaffected; "no reason" not to generate `--cov-report=html` in an untracked directory AFAIS. Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com> --- .github/workflows/run-tests.yaml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 656f11f..476acaa 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -60,7 +60,7 @@ jobs: - name: Test with tox env: FORCE_COLOR: 1 - PYTEST_CI_ARGS: --cov-report=xml --cov-report=html --junitxml=test_artifacts/test_report.xml --color=yes + PYTEST_CI_ARGS: --cov-report=xml --junitxml=test_artifacts/test_report.xml --color=yes run: tox ${{ matrix.python-version == '3.6' && '--skip-missing-interpreters=true' || '' }} - name: Upload coverage reports to Codecov diff --git a/pyproject.toml b/pyproject.toml index 9f4abc8..059659c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,7 @@ module = [ check_untyped_defs = true [tool.pytest.ini_options] -addopts = "--verbose --cov-config=pyproject.toml" +addopts = "--verbose --cov-config=pyproject.toml --cov-report=html" [tool.ruff] # ruff is less lenient than pylint and does not make any exceptions From 8edad6065f348759d20583b570db9156dba2bee7 Mon Sep 17 00:00:00 2001 From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:21:45 +0300 Subject: [PATCH 2/3] Fix tests running via PyCharm Would've been better to get the path via `requests.config.rootdir`, but it looks like a pain to inject the `requests` fixture here. Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com> --- tests/base_tester.py | 11 ++++++++++- tests/base_tester_test.py | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/base_tester.py b/tests/base_tester.py index 12d2e63..deed382 100644 --- a/tests/base_tester.py +++ b/tests/base_tester.py @@ -1,6 +1,7 @@ import os import sys from abc import ABC +from pathlib import Path from pprint import pprint from typing import Any, Dict, List @@ -21,6 +22,11 @@ pylint_pytest.checkers.fixture.FILE_NAME_PATTERNS = ("*",) +def get_test_root_path() -> Path: + """Assumes ``base_tester.py`` is at ``/tests``.""" + return Path(__file__).parent + + class BasePytestTester(ABC): CHECKER_CLASS = BaseChecker IMPACTED_CHECKER_CLASSES: List[BaseChecker] = [] @@ -41,7 +47,10 @@ def run_linter(self, enable_plugin): # pylint: disable-next=protected-access target_test_file = sys._getframe(1).f_code.co_name.replace("test_", "", 1) file_path = os.path.join( - os.getcwd(), "tests", "input", self.MSG_ID, target_test_file + ".py" + get_test_root_path(), + "input", + self.MSG_ID, + target_test_file + ".py", ) with open(file_path) as fin: diff --git a/tests/base_tester_test.py b/tests/base_tester_test.py index 4cf43ff..b40d510 100644 --- a/tests/base_tester_test.py +++ b/tests/base_tester_test.py @@ -1,9 +1,14 @@ import pytest -from base_tester import BasePytestTester +from base_tester import BasePytestTester, get_test_root_path # pylint: disable=unused-variable +def test_get_test_root_path(): + assert get_test_root_path().name == "tests" + assert (get_test_root_path() / "input").is_dir() + + def test_init_subclass_valid_msg_id(): some_string = "some_string" From d8db8e4cdca1c01ad66c74ba8923949a8aab35c8 Mon Sep 17 00:00:00 2001 From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> Date: Sat, 11 Nov 2023 23:53:27 +0200 Subject: [PATCH 3/3] Improve copy-paste docstring from 8756cc4627a66f150197519a2588512511f0c4f3 Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com> --- tests/input/unused-argument/func_param_as_fixture_arg.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/input/unused-argument/func_param_as_fixture_arg.py b/tests/input/unused-argument/func_param_as_fixture_arg.py index 003d194..90f0404 100644 --- a/tests/input/unused-argument/func_param_as_fixture_arg.py +++ b/tests/input/unused-argument/func_param_as_fixture_arg.py @@ -27,5 +27,8 @@ def test_nyfix(narg): # unused-argument @pytest.mark.parametrize("arg", [1, 2, 3]) def test_narg_is_used_nowhere(myfix, narg): - """A test function that uses the param through a fixture""" + """ + A test function that does not use its param (``narg``): + Not itself, nor through a fixture (``myfix``). + """ assert myfix