Skip to content

Commit

Permalink
Do not rely on the version number to know if the tests are present
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aerostitch authored and atodorov committed Dec 2, 2019
1 parent bdd1042 commit 23040e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ matrix:
- { stage: build_and_package_sanity, python: 3.6, env: SANITY_CHECK=1 }

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

install:
- pip install tox-travis
Expand Down
32 changes: 22 additions & 10 deletions pylint_django/tests/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@

import pylint

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

import test_functional # noqa: E402
try:
# pylint 2.5: test_functional has been moved to pylint.testutils
from pylint.testutils import FunctionalTestFile, LintModuleTest
except (ImportError, AttributeError):
# specify directly the directory containing test_functional.py
test_functional_dir = os.getenv('PYLINT_TEST_FUNCTIONAL_DIR', '')

# otherwise look for in in ~/pylint/tests - pylint 2.4
# this is the pylint git checkout dir, not the pylint module dir
if not os.path.isdir(test_functional_dir):
test_functional_dir = os.path.join(os.getenv('HOME', '/home/travis'), 'pylint', 'tests')

# or site-packages/pylint/test/ - pylint before 2.4
if not os.path.isdir(test_functional_dir):
test_functional_dir = os.path.join(os.path.dirname(pylint.__file__), 'test')

sys.path.append(test_functional_dir)

from test_functional import FunctionalTestFile, LintModuleTest


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


class PylintDjangoLintModuleTest(test_functional.LintModuleTest):
class PylintDjangoLintModuleTest(LintModuleTest):
"""
Only used so that we can load this plugin into the linter!
"""
Expand Down Expand Up @@ -53,7 +65,7 @@ def _file_name(test):
suite = []
for fname in os.listdir(input_dir):
if fname != '__init__.py' and fname.endswith('.py'):
suite.append(test_functional.FunctionalTestFile(input_dir, fname))
suite.append(FunctionalTestFile(input_dir, fname))

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

0 comments on commit 23040e3

Please sign in to comment.