From 6380e19f07f1958b9360e1c416060953b51cf147 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sat, 29 Aug 2015 16:53:57 -1000 Subject: [PATCH 1/2] Add notes to docstring of `monkeypatch.undo()` Note that calling `undo()` is generally not needed, and describe the "gotcha" discovered in #981. --- _pytest/monkeypatch.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/_pytest/monkeypatch.py b/_pytest/monkeypatch.py index d3a59327b..f7aa8cdbd 100644 --- a/_pytest/monkeypatch.py +++ b/_pytest/monkeypatch.py @@ -191,7 +191,17 @@ class monkeypatch: def undo(self): """ Undo previous changes. This call consumes the undo stack. Calling it a second time has no effect unless - you do more monkeypatching after the undo call.""" + you do more monkeypatching after the undo call. + + There is generally no need to call `undo()`, since it is + called automatically during tear-down. + + Note that the same `monkeypatch` fixture is used across a + single test invocation. If `monkeypatch` is used both by + the test function itself and one of the test fixtures, + calling `undo()` will undo all of the changes made in + both functions. + """ for obj, name, value in self._setattr: if value is not notset: setattr(obj, name, value) From 3a27cd87ceff6e85b4ff115fd6429bbab1054d7f Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sat, 29 Aug 2015 19:00:00 -1000 Subject: [PATCH 2/2] Adjust phrasing in monkeypatch.undo docstring s/test invocation/test function invocation/ --- _pytest/monkeypatch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/monkeypatch.py b/_pytest/monkeypatch.py index f7aa8cdbd..07998650a 100644 --- a/_pytest/monkeypatch.py +++ b/_pytest/monkeypatch.py @@ -197,7 +197,7 @@ class monkeypatch: called automatically during tear-down. Note that the same `monkeypatch` fixture is used across a - single test invocation. If `monkeypatch` is used both by + single test function invocation. If `monkeypatch` is used both by the test function itself and one of the test fixtures, calling `undo()` will undo all of the changes made in both functions.