Skip to content

Commit 8edad60

Browse files
committed
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 <[email protected]>
1 parent 90e4141 commit 8edad60

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

tests/base_tester.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
from abc import ABC
4+
from pathlib import Path
45
from pprint import pprint
56
from typing import Any, Dict, List
67

@@ -21,6 +22,11 @@
2122
pylint_pytest.checkers.fixture.FILE_NAME_PATTERNS = ("*",)
2223

2324

25+
def get_test_root_path() -> Path:
26+
"""Assumes ``base_tester.py`` is at ``<root>/tests``."""
27+
return Path(__file__).parent
28+
29+
2430
class BasePytestTester(ABC):
2531
CHECKER_CLASS = BaseChecker
2632
IMPACTED_CHECKER_CLASSES: List[BaseChecker] = []
@@ -41,7 +47,10 @@ def run_linter(self, enable_plugin):
4147
# pylint: disable-next=protected-access
4248
target_test_file = sys._getframe(1).f_code.co_name.replace("test_", "", 1)
4349
file_path = os.path.join(
44-
os.getcwd(), "tests", "input", self.MSG_ID, target_test_file + ".py"
50+
get_test_root_path(),
51+
"input",
52+
self.MSG_ID,
53+
target_test_file + ".py",
4554
)
4655

4756
with open(file_path) as fin:

tests/base_tester_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import pytest
2-
from base_tester import BasePytestTester
2+
from base_tester import BasePytestTester, get_test_root_path
33

44
# pylint: disable=unused-variable
55

66

7+
def test_get_test_root_path():
8+
assert get_test_root_path().name == "tests"
9+
assert (get_test_root_path() / "input").is_dir()
10+
11+
712
def test_init_subclass_valid_msg_id():
813
some_string = "some_string"
914

0 commit comments

Comments
 (0)