Skip to content

pylint complains about fs fixture name #609

Closed

Description

@AustinScola

I'm using the pytest pyfakefs fixture in a project. The project is linted with pylint. pylint warns C0103: Argument name "fs" doesn't conform to snake_case naming style (invalid-name). I know that I could add fs to the list of good-names for pylint, but I would prefer not to do that because then the name would be accepted everywhere. I could also add # pylint: disable=invalid-name everywhere I use the fixture, but that isn't very clean.

Could we add another name for the pytest fixture? Something like fake_filesystem?

Activity

  1. mrbean-bremen commented on Jun 7, 2021

    @mrbean-bremen
    Member

    Hm, fs is indeed a bit short, but it's also handy and it's quite clear that it stands for file system. I want to avoid polluting the fixture namespace with aliases that cannot be disabled, so I think the way to go here is to define your own fixture:

    conftest.py

    @pytest.fixture
    def fake_filesystem(fs):  # pylint:disable=invalid-name
        yield fs

    and use fake_filesystem everywhere else. We could add this as a default, but at the moment I'm more inclined not to do this.

    @jmcgeheeiv - what do you think?

  2. jmcgeheeiv commented on Jun 7, 2021

    @jmcgeheeiv
    Contributor

    I like @mrbean-bremen's workaround. We could add it to our pytest template, which would avoid polluting the namespace, yet everybody sees it and can use it to avoid the PyLint issue if they like.

  3. AustinScola commented on Jun 7, 2021

    @AustinScola
    ContributorAuthor

    I like @mrbean-bremen's workaround too. Not polluting the namespace sounds like a good reason. Thanks for the suggestion!

    As a side note, something else I thought of is that there might be some weird behavior if both the fs and fake_filesystem fixtures are used in the same unit test?

  4. mrbean-bremen commented on Jun 8, 2021

    @mrbean-bremen
    Member

    there might be some weird behavior if both the fs and fake_filesystem fixtures are used in the same unit test

    No, they will both point to the same fake fs and can be used interchangeably:

    def test_both_fixtures(fs, fake_filesystem):
        fake_filesystem.create_file('/var/data/xx1.txt')
        fs.create_file('/var/data/xx2.txt')
        assert os.path.exists('/var/data/xx1.txt')
        assert os.path.exists('/var/data/xx2.txt')
        assert fs == fake_filesystem
  5. mrbean-bremen commented on Jun 10, 2021

    @mrbean-bremen
    Member

    I'm converting this into a discussion Q/A issue.

  6. locked and limited conversation to collaborators on Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions