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

Docs: using pytest.mark.usefixtures in code snippets #834

Closed
jamesbraza opened this issue May 26, 2023 · 1 comment · Fixed by #842
Closed

Docs: using pytest.mark.usefixtures in code snippets #834

jamesbraza opened this issue May 26, 2023 · 1 comment · Fixed by #842

Comments

@jamesbraza
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Many of the pytest-oriented examples in https://pytest-pyfakefs.readthedocs.io/en/stable/usage.html use a fake_fs fixture in the test signature, but don't actually use it in the test body.

Here's a more specific example: https://pytest-pyfakefs.readthedocs.io/en/stable/usage.html#access-to-files-in-the-real-file-system

def test_using_fixture1(my_fs):  # Linters don't like this line
    with open(os.path.join(fixture_path, "fixture1.txt")) as f:
        contents = f.read()

Multiple linters detect this line as unused code:

  • pylint: invalid-name gets emitted on test functions or methods
  • flake8-unused-arguments: ARG001 gets emitted if test function, or ARG002 gets emitted if test method

Describe the solution you'd like

This can be ameliorated with using pytest.mark.usefixtures decorator:

@pytest.mark.usefixtures("my_fs")
def test_using_fixture1():
    with open(os.path.join(fixture_path, "fixture1.txt")) as f:
        contents = f.read()

Can we move code snippets in the pyfakefs docs to use pytest.mark.usefixtures?

@mrbean-bremen
Copy link
Member

Thanks, this would make sense, probably with a line explaining it.
If you want to make a PR, go ahead - otherwise this gets at the end of my personal backlog 😀

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Jun 10, 2023
- avoids linter warning about unused argument
- closes pytest-dev#834
mrbean-bremen added a commit that referenced this issue Jun 11, 2023
- avoids linter warning about unused argument
- closes #834
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants