Skip to content

pylint does not suppress all false positives #78

Open
@tslever

Description

@tslever

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions