Switch monkeypatch fixture to yield syntax
This commit is contained in:
parent
b769e41d8f
commit
6d81c684cc
1
AUTHORS
1
AUTHORS
|
@ -71,6 +71,7 @@ Janne Vanhala
|
|||
Jason R. Coombs
|
||||
Javier Domingo Cansino
|
||||
Javier Romero
|
||||
Jeff Widman
|
||||
John Towler
|
||||
Jon Sonesen
|
||||
Jordan Guymon
|
||||
|
|
|
@ -11,7 +11,7 @@ RE_IMPORT_ERROR_NAME = re.compile("^No module named (.*)$")
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def monkeypatch(request):
|
||||
def monkeypatch():
|
||||
"""The returned ``monkeypatch`` fixture provides these
|
||||
helper methods to modify objects, dictionaries or os.environ::
|
||||
|
||||
|
@ -30,8 +30,8 @@ def monkeypatch(request):
|
|||
will be raised if the set/deletion operation has no target.
|
||||
"""
|
||||
mpatch = MonkeyPatch()
|
||||
request.addfinalizer(mpatch.undo)
|
||||
return mpatch
|
||||
yield mpatch
|
||||
mpatch.undo()
|
||||
|
||||
|
||||
def resolve(name):
|
||||
|
|
|
@ -7,16 +7,12 @@ from _pytest.monkeypatch import MonkeyPatch
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def mp(request):
|
||||
def mp():
|
||||
cwd = os.getcwd()
|
||||
sys_path = list(sys.path)
|
||||
|
||||
def cleanup():
|
||||
sys.path[:] = sys_path
|
||||
os.chdir(cwd)
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
return MonkeyPatch()
|
||||
yield MonkeyPatch()
|
||||
sys.path[:] = sys_path
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
def test_setattr():
|
||||
|
@ -329,5 +325,3 @@ def test_issue1338_name_resolving():
|
|||
monkeypatch.delattr('requests.sessions.Session.request')
|
||||
finally:
|
||||
monkeypatch.undo()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue