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

I want a rule that will disallow patching os.environ with mock.patch.dict #252

Open
harupy opened this issue Jul 29, 2023 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@harupy
Copy link

harupy commented Jul 29, 2023

First of all, thank you for developing this amazing flake8 plugin. I love it :)

Rule request

I want a rule that will disallow patching os.environ with mock.patch.dict:

from unittests import mock

def test_foo():
    with mock.patch.dict(os.environ, {"FOO": ...}):
        ...

    with mock.patch.dict(os.environ, {}):
        ...

Instead, we should use monkeypatch.setenv or monkeypatch.delenv to set or remove relevant environment variables. This also helps simply the code.

def test_foo(monkeypatch):
    monkeypatch.setenv("FOO", ...)
    ...

    monkeypatch.delenv("FOO")
    ...

Description

Rationale

@harupy harupy added the enhancement New feature or request label Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant