Monkey Patching functions - Fixtures and Mocking in Python
Keyboard shortcuts
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
Monkey Patching functions
def run(x):
return 2 * x
import aut
def test_a():
assert aut.run(7) == 14
def test_b(monkeypatch):
monkeypatch.setattr('aut.run', lambda z: z)
assert aut.run(5) == 5
def test_c():
assert aut.run(10) == 20