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

pylint does not suppress all false positives #78

Open
tslever opened this issue Jul 17, 2024 · 2 comments
Open

pylint does not suppress all false positives #78

tslever opened this issue Jul 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@tslever
Copy link

tslever commented Jul 17, 2024

Describe the bug
Modules test_cleaner.py, test_tokenizer.py, test_word_counter.py, and test_system.py all import fixture temporary_directory_of_files_with_texts. This fixture calls fixture temporary_directory. Using fixture temporary_directory_of_files_with_texts requires importing both fixtures.

To Reproduce
Package versions

  • pylint: 3.2.3
  • pytest: 8.2.0
  • pylint-pytest: 1.1.8

(add any relevant pylint/pytest plugin here)

Folder structure

$ tree -L 2

.
├── LICENSE
├── README.md
├── Text_IDs.csv
├── __pycache__
│   ├── conftest.cpython-310-pytest-8.2.0.pyc
│   └── conftest.cpython-310-pytest-8.2.2.pyc
├── clean_text.sh
├── conftest.py
├── env
│   ├── bin
│   ├── include
│   ├── lib
│   ├── lib64 -> lib
│   └── pyvenv.cfg
├── get_the_books.sh
├── makefile
├── pylintrc
├── pyproject.toml
├── pytest.ini
├── pytest.log
├── requirements.txt
├── src
│   ├── __init__.py
│   ├── __pycache__
│   └── pkg_tsl2b
└── tests
    ├── __pycache__
    ├── fixtures.py
    ├── test_cleaner.py
    ├── test_system.py
    ├── test_that_fails.py
    ├── test_tokenizer.py
    ├── test_word_counter.py
    └── utilities.py

File content

tests/fixtures.py:

...

@pytest.fixture(scope = "session")
def temporary_directory(tmp_path_factory) -> pathlib.PosixPath:
    '''
    Provides a pathlib.PosixPath object for a temporary directory

    Keyword arguments:
        tmp_path_factory

    Return values:
        temporary_directory: pathlib.PosixPath -- a pathlib.PosixPath object for a temporary directory

    Side effects:
        none

    Exceptions raised:
        none

    Restrictions of when this is called:
        This function is called automatically by pytest.
    '''

    temp_dir = tmp_path_factory.mktemp("temporary_directory")
    return temp_dir


@pytest.fixture(params = [dictionary_of_IDs_and_base_names_of_texts], scope = "session")
def temporary_directory_of_files_with_texts(request: pytest.FixtureRequest, temporary_directory) -> pathlib.PosixPath:
    '''
    Provides a pathlib.PosixPath object for a temporary directory of files with texts

    Keyword arguments:
        request: pytest.FixtureRequest -- a request from which to get a specified parameter
        temporary_directory

    Return values:
        temporary_directory

    Side effects:
        Creates files with texts

    Exceptions raised:
        none

    Restrictions on when this is called:
        This function is called automatically by pytest
    '''

    ...

    return temporary_directory

...

tests/test_system.py:

...

from fixtures import logger, temporary_directory, temporary_directory_of_files_with_texts

...

@pytest.mark.integration
def test_downloading_cleaning_tokenizing_and_counting_words_in_the_raven(
    logger,
    temporary_directory_of_files_with_texts
):

...

pylint output with the plugin

find . -path ./env -prune -o -name "*.py" -exec pylint --load_plu
gins pylint_pytest {} +
************* Module test_word_counter
tests/test_word_counter.py:11:0: W0611: Unused temporary_directory imported from fixtures (unused-import)
************* Module test_tokenizer
tests/test_tokenizer.py:10:0: W0611: Unused temporary_directory imported from fixtures (unused-import)
************* Module test_system
tests/test_system.py:7:0: W0611: Unused temporary_directory imported from fixtures (unused-import)
************* Module test_cleaner
tests/test_cleaner.py:10:0: W0611: Unused temporary_directory imported from fixtures (unused-import)

(Optional) pytest output from fixture collection

$ pytest --fixtures --collect-only <path/to/test/module.py>
<paste output here, can omit the built-ins>

Expected behavior
I expected these pylint false positives to be suppressed.

Additional context
Add any other context about the problem here.

@tslever tslever added the bug Something isn't working label Jul 17, 2024
@stdedos
Copy link
Collaborator

stdedos commented Jul 17, 2024

I would appreciate if you gave me some (scrubbed) example code, as it can help with https://github.com/pylint-dev/pylint-pytest/tree/master/tests/input/unused-import

@tslever
Copy link
Author

tslever commented Jul 17, 2024

@stdedos , I have added example code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants