[TIP] Pylint error with pytest function/method lever marker - class level marker works

holger krekel holger at merlinux.eu
Wed Jul 11 23:35:35 PDT 2012


Hui Baiju,

On Wed, Jul 11, 2012 at 22:41 +0530, Baiju M wrote:
> Hi,
> 
> When I use a function or method lever marker, pylint is throwing this error:
> 
> $ pylint test_hello.py
> No config file found, using default configuration
> ************* Module test_hello
> C:  1,0: Missing docstring
> Traceback (most recent call last):
>   File "/home/baiju/pylintve/bin/pylint", line 4, in <module>
>     lint.Run(sys.argv[1:])
>   File "/home/baiju/pylintve/lib/python2.6/site-packages/pylint/lint.py",
> line 879, in __init__
>     linter.check(args)
>   File "/home/baiju/pylintve/lib/python2.6/site-packages/pylint/lint.py",
> line 502, in check
>     self.check_astng_module(astng, walker, rawcheckers)
>   File "/home/baiju/pylintve/lib/python2.6/site-packages/pylint/lint.py",
> line 574, in check_astng_module
>     walker.walk(astng)
>   File "/home/baiju/pylintve/lib/python2.6/site-packages/pylint/utils.py",
> line 528, in walk
>     self.walk(child)
>   File "/home/baiju/pylintve/lib/python2.6/site-packages/pylint/utils.py",
> line 525, in walk
>     cb(astng)
>   File
> "/home/baiju/pylintve/lib/python2.6/site-packages/pylint/checkers/base.py",
> line 161, in visit_function
>     if not redefined_by_decorator(node):
>   File
> "/home/baiju/pylintve/lib/python2.6/site-packages/pylint/checkers/base.py",
> line 116, in redefined_by_decorator
>     decorator.expr.name == node.name):
> AttributeError: 'Getattr' object has no attribute 'name'
> 
> 
> This is the test_hello.py:
> 
> import pytest
> 
> 
> @pytest.mark.simple
> def test_simple_hello():
>     import hello
>     assert hello.say_hello() == "Hello"
> 
> I have kept the full traceback with all steps to reproduce this issue here:
> 
> https://gist.github.com/3091659
> 
> If I use class level markers, pylint is not throwing any error.  So, I am
> not
> sure whether this is a pytest issue or pylint issue.

Not sure what exactly causes this but it's a known limitation that pylint
cannot deal with dynamic namespaces.  The "pytest.mark" object is provided
by a plugin and thus not visible by the AST-parsing that pylint does.
I don't know of a way to tell pylint to accept the object.

pytest may in the future remove this dynamism for the builtin plugins so
that pylint has less problems.  Meanwhile you might also want to check
out the PEP8 checker which also performs a number of sanity/code level
checks, see http://pypi.python.org/pypi/pytest-pep8

best,
holger

> Regards,
> Baiju M

> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python




More information about the testing-in-python mailing list