Fix mistakes in monkeypatch doc example

This commit is contained in:
Brianna Laugher 2011-02-18 16:52:18 +11:00
parent 27577170e1
commit f6c1e49287
1 changed files with 2 additions and 2 deletions

View File

@ -24,14 +24,14 @@ patch this function before calling into a function which uses it::
import os.path import os.path
def getssh(): # pseudo application code def getssh(): # pseudo application code
return os.path.join(os.expanduser("~admin"), '.ssh') return os.path.join(os.path.expanduser("~admin"), '.ssh')
def test_mytest(monkeypatch): def test_mytest(monkeypatch):
def mockreturn(path): def mockreturn(path):
return '/abc' return '/abc'
monkeypatch.setattr(os.path, 'expanduser', mockreturn) monkeypatch.setattr(os.path, 'expanduser', mockreturn)
x = getssh() x = getssh()
assert x == '/abc' assert x == '/abc/.ssh'
After the test function finishes the ``os.path.expanduser`` modification After the test function finishes the ``os.path.expanduser`` modification
will be undone. will be undone.