Skip to content

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

@harupy

Description

@harupy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions