pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Mention `monkeypatch.undo()` in the docs

Open webknjaz opened this issue 3 years ago • 1 comments

It was never mentioned in the docs, and I keep forgetting that it's .undo() and not .stopall() or something...

  • [ ] Include documentation when adding new features.
  • [ ] Include new tests or update existing tests when applicable.
  • [ ] Allow maintainers to push and squash when merging my commits. Please uncheck this if you prefer to squash the commits yourself.

webknjaz avatar Aug 05 '22 22:08 webknjaz

Given how monkeypatch works, undo undoes all of them, using the context context manager may be the better detail to recommend

RonnyPfannschmidt avatar Aug 06 '22 03:08 RonnyPfannschmidt

Given how monkeypatch works, undo undoes all of them, using the context context manager may be the better detail to recommend

Why not both? We added .context() in #10143.

The-Compiler avatar Aug 12 '22 09:08 The-Compiler

Undo is a footgun that may undo patches of other fixtures

RonnyPfannschmidt avatar Aug 12 '22 09:08 RonnyPfannschmidt

In fact, since we have contex, I'm in favour of deprecation of undo

RonnyPfannschmidt avatar Aug 12 '22 09:08 RonnyPfannschmidt

In fact, since we have contex, I'm in favour of deprecation of undo

I would prefer not... this would force all users to update perfectly working code.

I think a better approach would to update the undo() docs to strongly recommend using a context() instead.

nicoddemus avatar Aug 12 '22 11:08 nicoddemus

I think a better approach would to update the undo() docs to strongly recommend using a context() instead.

Took the liberty of doing that and pushing it to this branch. Also improved the docs a bit by adding cross-links.

nicoddemus avatar Aug 12 '22 11:08 nicoddemus

@nicoddemus i believe that there are next to no valid uses of undo, as it always affects the whole monkeypatch object, which is not safely usable in most cases

RonnyPfannschmidt avatar Aug 12 '22 12:08 RonnyPfannschmidt

@RonnyPfannschmidt you are commenting about deprecating undo(), right? If so I think we should move that discussion to a new issue/proposal.

Or do you mean to have new changes in the PR?

nicoddemus avatar Aug 12 '22 12:08 nicoddemus

True, let's move that into a own task

RonnyPfannschmidt avatar Aug 12 '22 12:08 RonnyPfannschmidt

@RonnyPfannschmidt (and others), regardless of the discussion about deprecating undo(), I think the PR is still good to be merged. 👍

nicoddemus avatar Aug 12 '22 14:08 nicoddemus

Thanks @RonnyPfannschmidt! 👍

@webknjaz would appreciate if you could take a look at my changes too. 😁

nicoddemus avatar Aug 12 '22 14:08 nicoddemus

@nicoddemus love the improvements, thanks!

webknjaz avatar Aug 13 '22 19:08 webknjaz