I want to use the pytest monkeypatch plugin, but I can't figure out how to import it. I've tried:
import monkeypath
import pytest.monkeypatch
from pytest import monkeypatch
monkeypatch is a part of the pytest-mock library that allows you to intercept what a function would normally do, substituting its full execution with a return value of your own specification.
The monkeypatch fixture helps you to safely set/delete an attribute, dictionary item or environment variable, or to modify sys. path for importing. The monkeypatch fixture provides these helper methods for safely patching and mocking functionality in tests: monkeypatch.
It's not a plugin, it's a built-in pytest fixture.
In a nutshell, that means you simply write a test with a monkeypatch
argument, and the test will get the monkeypatch object as that argument.
The page you linked has a simple example:
def test_some_interaction(monkeypatch):
monkeypatch.setattr("os.getcwd", lambda: "/")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With