Skip to content

Commit

Permalink
[FIX] test-folder-imported: check if node has a modname as attribute
Browse files Browse the repository at this point in the history
In python versions above 3.5, an error occurs when try to get 'modname' from node.
  • Loading branch information
fernandahf committed Jan 19, 2021
1 parent 9504bf0 commit 7dd59fa
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pylint_odoo/checkers/modules_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,15 @@ def check_odoo_relative_import(self, node):

def check_folder_test_imported(self, node):
if (hasattr(node.parent, 'file')
and os.path.basename(node.parent.file) == '__init__.py'
and ("tests" in [item for item, _ in node.names]
or "tests" in node.modname)):
self.add_message('test-folder-imported', node=node,
args=(node.parent.name,))
and os.path.basename(node.parent.file) == '__init__.py'):
package_names = []
if isinstance(node, astroid.ImportFrom):
package_names = node.modname.split('.')[:1]
elif isinstance(node, astroid.Import):
package_names = [name[0].split('.')[0] for name in node.names]
if "tests" in package_names:
self.add_message('test-folder-imported', node=node,
args=(node.parent.name,))

@staticmethod
def _is_absolute_import(node, name):
Expand Down

0 comments on commit 7dd59fa

Please sign in to comment.