Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test failure test_by_module_statement_value #3198

Closed
FRidh opened this issue Oct 17, 2019 · 5 comments
Closed

test failure test_by_module_statement_value #3198

FRidh opened this issue Oct 17, 2019 · 5 comments
Labels

Comments

@FRidh
Copy link

FRidh commented Oct 17, 2019

Steps to reproduce

  1. Checkout repo at 2.4.2
  2. Have Python env (issue occurs with 3.7 and 3.8, not tested with other versions)
  3. pytest

Current behavior

=================================== FAILURES ===================================
________________________ test_by_module_statement_value ________________________

init_linter = Checker 'master' (responsible for 'F0001', 'F0002', 'F0010', 'I0001', 'I0010', 'I0011', 'I0013', 'I0020', 'I0021', 'I0022', 'E0001', 'E0011', 'E0012')

    def test_by_module_statement_value(init_linter):
        """Test "statement" for each module analized of computed correctly."""
        linter = init_linter
        linter.check(os.path.join(os.path.dirname(__file__), "data"))

        for module, module_stats in linter.stats["by_module"].items():

            linter2 = init_linter
            if module == "data":
                linter2.check(os.path.join(os.path.dirname(__file__), "data/__init__.py"))
            else:
                linter2.check(os.path.join(os.path.dirname(__file__), module))

            # Check that the by_module "statement" is equal to the global "statement"
            # computed for that module
>           assert module_stats["statement"] == linter2.stats["statement"]
E           assert 7 == 0

tests/unittest_lint.py:811: AssertionError

Expected behavior

Test to pass.

pylint --version output

pylint is at 2.4.2.

============================= test session starts ==============================
platform linux -- Python 3.8.0, pytest-5.2.1, py-1.8.0, pluggy-0.13.0

@stanislavlevin
Copy link
Contributor

stanislavlevin commented Oct 17, 2019

@FRidh, hi. Today I faced the same issue.
The reason is not obvious at first.
In my case, this is a dot within the pathname:

796     def test_by_module_statement_value(init_linter):
797         """Test "statement" for each module analized of computed correctly."""
798         linter = init_linter
799         linter.check(os.path.join(os.path.dirname(__file__), "data"))
800  
801         for module, module_stats in linter.stats["by_module"].items():
802  
803             linter2 = init_linter
804             if module == "data":
805                 linter2.check(os.path.join(os.path.dirname(__file__), "data/__init__.py"))
(Pdb) os.path.dirname(__file__)
'/usr/src/RPM/BUILD/python3-module-pylint-2.4.2/tests'
(Pdb) p module
'data.suppliermodule_test'

Thus, the linter gets on its input the dotted name with module notation.
Then

> /usr/src/RPM/BUILD/python3-module-pylint-2.4.2/.tox/py37/lib/python3/site-packages/pylint/utils/utils.py(143)expand_modules()
-> filepath = modutils.file_from_modpath(modname.split("."))
(Pdb) modutils.file_from_modpath(modname.split("."))
(Pdb) modname.split(".")
['/usr/src/RPM/BUILD/python3-module-pylint-2', '4', '2/tests/data', 'suppliermodule_test']
(Pdb) modutils.file_from_modpath(modname.split("."))

Thus, expand_modules just doesn't expect the dot name and the in-line PyLinter unable to find this module.
This is the same as:

import pylint.lint
pylint.lint.Run(["/test/dot.name/tests.module"])

while the following works:

import pylint.lint
pylint.lint.Run(["/test/notdotname/tests.module"])

@stanislavlevin
Copy link
Contributor

astroid takes args from pylint and works as expected.

from astroid import modutils
modutils.file_info_from_modpath(["/test/dot.name/tests", "module"])

So, in my opinion expand_modules doesn't handle properly.

@PCManticore
Copy link
Contributor

Thanks @stanislavlevin for the investigation, appreciate it!

@sandrotosi
Copy link
Contributor

yep this is still happening with 2.4.4:

=================================== FAILURES ===================================
________________________ test_by_module_statement_value ________________________

init_linter = Checker 'master' (responsible for 'F0001', 'F0002', 'F0010', 'I0001', 'I0010', 'I0011', 'I0013', 'I0020', 'I0021', 'I0022', 'E0001', 'E0011', 'E0012')

    def test_by_module_statement_value(init_linter):
        """Test "statement" for each module analized of computed correctly."""
        linter = init_linter
        linter.check(os.path.join(os.path.dirname(__file__), "data"))
    
        for module, module_stats in linter.stats["by_module"].items():
    
            linter2 = init_linter
            if module == "data":
                linter2.check(os.path.join(os.path.dirname(__file__), "data/__init__.py"))
            else:
                linter2.check(os.path.join(os.path.dirname(__file__), module))
    
            # Check that the by_module "statement" is equal to the global "statement"
            # computed for that module
>           assert module_stats["statement"] == linter2.stats["statement"]
E           assert 20 == 0

tests/unittest_lint.py:811: AssertionError

@DanielNoord
Copy link
Collaborator

I'm going to close this as the CI is passing and we haven't received many reports about this in recent years.

@DanielNoord DanielNoord closed this as not planned Won't fix, can't repro, duplicate, stale Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants