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

Missing Attribute Error on pytest.fixture #6331

Closed
MisterBianco opened this issue Feb 4, 2019 · 6 comments
Closed

Missing Attribute Error on pytest.fixture #6331

MisterBianco opened this issue Feb 4, 2019 · 6 comments

Comments

@MisterBianco
Copy link

Please provide more information to help us understand the issue:

This is potentially both a bug and a feature request.

@pytest.mark.incremental
@pytest.mark.usefixtures("driver")
class TestNeatLogin(object):
    def test_hello(self) -> None:

        self.driver << Neat().home_page
        assert "hi" in self.driver.url

self.driver is the pytest fixture from a conftest file and is just a wrapper for selenium (unimportant)

Output of mypy --disallow-untyped-defs --ignore-missing-imports test_neat.py:

test_neat.py:18: error: "TestNeatLogin" has no attribute "driver"

I was hoping it would detect the fixture and move on

Environ:

    mypy: 0.660
   python: 3.7

I can try installing from master if anyone feels like that will fix the issue, just curious what I can do to either: fix the issue or ignore these particular errors.

@ilevkivskyi
Copy link
Member

There is no way mypy can detect this. Potentially, one can write a mypy plugin (but again mypy core team has no bandwidth for this). Your best choice for now is just to use # type: ignore to silence the error.

@MisterBianco
Copy link
Author

Ok thank you, I assume the comment is put at the top of the source file?

@ilevkivskyi
Copy link
Member

On the line with error.

@MisterBianco
Copy link
Author

Is there a way to ignore all instances of the same error?
Since it generates like 40 errors of the same type?

@ilevkivskyi
Copy link
Member

Ignoring part of a file is not implemented yet, see #626. You can however just add ignore_errors = True for that file(s) in mypy.ini (some people do this for tests, because fixtures and mocks cause many false positives).

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 5, 2019

It may also be helpful to explicitly declare the attribute that mypy thinks is missing in the class body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants