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

Pytest fixtures triggers unused-import even when required by tests #3493

Closed
Pierre-Sassoulas opened this issue Apr 20, 2020 · 3 comments · Fixed by #3496
Closed

Pytest fixtures triggers unused-import even when required by tests #3493

Pierre-Sassoulas opened this issue Apr 20, 2020 · 3 comments · Fixed by #3496
Assignees

Comments

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Apr 20, 2020

Steps to reproduce

in pylint's tests in tests/message/generic_fixtures.py:

import pytest

@pytest.fixture
def empty_msgid_store():
    return MessageIdStore()

In test/message/unittest_message_id_store.py :

from .generic_fixtures import empty_msgid_store

def test_get_message_ids_not_existing(empty_msgid_store):
    with pytest.raises(UnknownMessageError) as error:
        w9876 = "W9876"
        empty_msgid_store.get_active_msgids(w9876)
    assert w9876 in str(error.value)

Current behavior

tests/message/unittest_message_id_store.py:8:0: W0611: Unused empty_msgid_store imported from generic_fixtures (unused-import)

Expected behavior

No error.

pylint --version output

pylint 2.5.0-dev1
astroid 2.4.0
Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0]
@Pierre-Sassoulas
Copy link
Member Author

pytest import implicitly fixtures if placed in a file named conftest.py at the root of the directory. Here the generic_fixtures.py can be renamed conftest.py and the import can be removed. See latest commit and https://docs.pytest.org/en/2.7.3/plugins.html?highlight=re

@jamesbraza
Copy link

An updated pytest plugins link is: https://docs.pytest.org/en/stable/reference/plugin_list.html

Please forgive me for grave digging this. @Pierre-Sassoulas why did you link to the plugins page here? What plugin was useful for this issue?

@Pierre-Sassoulas
Copy link
Member Author

Hmm, well I have no idea myself, seem like I searched for "re" on the page seeing the get argument, which is also confusing (?!). After re-reading the commit content, I would make sense that I'd link to the conftest.py doc (?)

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

Successfully merging a pull request may close this issue.

2 participants