Skip to content

Commit 23040e3

Browse files
aerostitchatodorov
authored andcommitted
Do not rely on the version number to know if the tests are present
instead make use of PYLINT_TEST_FUNCTIONAL_DIR env variable. This is only useful if you are trying to run the test suite and build a new package! Apparently some distributions (Debian) add back the tests/ directory into the package so they can import test_functional.py from there! In Travis CI - use the 2.4 branch for testing
1 parent bdd1042 commit 23040e3

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ matrix:
2727
- { stage: build_and_package_sanity, python: 3.6, env: SANITY_CHECK=1 }
2828

2929
before_install:
30-
- git clone --depth 1 https://github.com/PyCQA/pylint.git ~/pylint
30+
- git clone --depth 1 https://github.com/PyCQA/pylint.git --branch 2.4 --single-branch ~/pylint
3131

3232
install:
3333
- pip install tox-travis

pylint_django/tests/test_func.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@
55

66
import pylint
77

8-
if pylint.__version__ >= '2.4':
9-
# after version 2.4 pylint stopped shipping the test directory
10-
# as part of the package so we check it out locally for testing
11-
sys.path.append(os.path.join(os.getenv('HOME', '/home/travis'), 'pylint', 'tests'))
12-
else:
13-
# because there's no __init__ file in pylint/test/
14-
sys.path.append(os.path.join(os.path.dirname(pylint.__file__), 'test'))
158

16-
import test_functional # noqa: E402
9+
try:
10+
# pylint 2.5: test_functional has been moved to pylint.testutils
11+
from pylint.testutils import FunctionalTestFile, LintModuleTest
12+
except (ImportError, AttributeError):
13+
# specify directly the directory containing test_functional.py
14+
test_functional_dir = os.getenv('PYLINT_TEST_FUNCTIONAL_DIR', '')
15+
16+
# otherwise look for in in ~/pylint/tests - pylint 2.4
17+
# this is the pylint git checkout dir, not the pylint module dir
18+
if not os.path.isdir(test_functional_dir):
19+
test_functional_dir = os.path.join(os.getenv('HOME', '/home/travis'), 'pylint', 'tests')
20+
21+
# or site-packages/pylint/test/ - pylint before 2.4
22+
if not os.path.isdir(test_functional_dir):
23+
test_functional_dir = os.path.join(os.path.dirname(pylint.__file__), 'test')
24+
25+
sys.path.append(test_functional_dir)
26+
27+
from test_functional import FunctionalTestFile, LintModuleTest
28+
1729

1830
# alter sys.path again because the tests now live as a subdirectory
1931
# of pylint_django
@@ -22,7 +34,7 @@
2234
sys.path.append(os.path.join(os.path.dirname(__file__), 'input'))
2335

2436

25-
class PylintDjangoLintModuleTest(test_functional.LintModuleTest):
37+
class PylintDjangoLintModuleTest(LintModuleTest):
2638
"""
2739
Only used so that we can load this plugin into the linter!
2840
"""
@@ -53,7 +65,7 @@ def _file_name(test):
5365
suite = []
5466
for fname in os.listdir(input_dir):
5567
if fname != '__init__.py' and fname.endswith('.py'):
56-
suite.append(test_functional.FunctionalTestFile(input_dir, fname))
68+
suite.append(FunctionalTestFile(input_dir, fname))
5769

5870
# when testing the db_performance plugin we need to sort by input file name
5971
# because the plugin reports the errors in close() which appends them to the

0 commit comments

Comments
 (0)