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
|
Jason R. Coombs
|
||||||
Javier Domingo Cansino
|
Javier Domingo Cansino
|
||||||
Javier Romero
|
Javier Romero
|
||||||
|
Jeff Widman
|
||||||
John Towler
|
John Towler
|
||||||
Jon Sonesen
|
Jon Sonesen
|
||||||
Jordan Guymon
|
Jordan Guymon
|
||||||
|
|
|
@ -11,7 +11,7 @@ RE_IMPORT_ERROR_NAME = re.compile("^No module named (.*)$")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def monkeypatch(request):
|
def monkeypatch():
|
||||||
"""The returned ``monkeypatch`` fixture provides these
|
"""The returned ``monkeypatch`` fixture provides these
|
||||||
helper methods to modify objects, dictionaries or os.environ::
|
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.
|
will be raised if the set/deletion operation has no target.
|
||||||
"""
|
"""
|
||||||
mpatch = MonkeyPatch()
|
mpatch = MonkeyPatch()
|
||||||
request.addfinalizer(mpatch.undo)
|
yield mpatch
|
||||||
return mpatch
|
mpatch.undo()
|
||||||
|
|
||||||
|
|
||||||
def resolve(name):
|
def resolve(name):
|
||||||
|
|
|
@ -7,17 +7,13 @@ from _pytest.monkeypatch import MonkeyPatch
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mp(request):
|
def mp():
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
sys_path = list(sys.path)
|
sys_path = list(sys.path)
|
||||||
|
yield MonkeyPatch()
|
||||||
def cleanup():
|
|
||||||
sys.path[:] = sys_path
|
sys.path[:] = sys_path
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
|
|
||||||
request.addfinalizer(cleanup)
|
|
||||||
return MonkeyPatch()
|
|
||||||
|
|
||||||
|
|
||||||
def test_setattr():
|
def test_setattr():
|
||||||
class A:
|
class A:
|
||||||
|
@ -329,5 +325,3 @@ def test_issue1338_name_resolving():
|
||||||
monkeypatch.delattr('requests.sessions.Session.request')
|
monkeypatch.delattr('requests.sessions.Session.request')
|
||||||
finally:
|
finally:
|
||||||
monkeypatch.undo()
|
monkeypatch.undo()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue