Using PyLint with Squish test scripts that use source()

Last edited on

PyLint does not know about Squish's source() (or findFile()) functions. Therefore extra measures are required to use PyLint on Squish test scripts which use these functions.

Here is an example Python test case script and a file with utility functions which resides in the same folder as test.py:

"""module doc string"""

source(findFile("scripts", "utils.py"))

def main():
    """Dummy docstring"""

    print "In main()"
    utils_func()
    test_func()

def test_func():
    """Dummy docstring"""

    print "In test_func()"
test.py
"""Dummy docstring"""

def utils_func():
    """Dummy docstring"""

    print "In utils_func()"
utils.py

PyLint output for this:

C:\Users\myuser\suite_mine\tst_first> python -m pylint test.py
No config file found, using default configuration
************* Module test
E:  3, 0: Undefined variable 'source' (undefined-variable)
E:  3, 7: Undefined variable 'findFile' (undefined-variable)
E:  9, 4: Undefined variable 'utils_func' (undefined-variable)

[...]

Global evaluation
-----------------
Your code has been rated at -11.43/10 (previous run: ...)
Executing in cmd.exe

To avoid these errors:

"""module doc string"""



# FOR PYLINT - START
if not source:
    def findFile(file_type, filename): # pylint: disable=invalid-name,missing-docstring,unused-argument
        pass

    def source(filename): # pylint: disable=missing-docstring,unused-argument
        pass

if not source: # pylint: disable=using-constant-test
    # These require that PYTHONPATH includes
    # all folders with these module files:
    from utils import * # pylint: disable=wildcard-import
# FOR PYLINT - END



source(findFile("scripts", "utils.py"))



def main():
    """Dummy docstring"""

    print "In main()"
    utils_func()
    test_func()

def test_func():
    """Dummy docstring"""

    print "In test_func()"
test.py

PyLint output for this:

C:\Users\myuser\suite_mine\tst_first> python -m pylint test.py
No config file found, using default configuration
************* Module test
I:  7, 0: Locally disabling invalid-name (C0103) (locally-disabled)
I:  7, 0: Locally disabling missing-docstring (C0111) (locally-disabled)
I:  7, 0: Locally disabling unused-argument (W0613) (locally-disabled)
I: 10, 0: Locally disabling missing-docstring (C0111) (locally-disabled)
I: 10, 0: Locally disabling unused-argument (W0613) (locally-disabled)
I: 13, 0: Locally disabling using-constant-test (W0125) (locally-disabled)
I: 16, 0: Locally disabling wildcard-import (W0401) (locally-disabled)

[...]

Global evaluation
-----------------
Your code has been rated at 10.00/10 (previous run: ...)
Executing in cmd.exe