-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
monkeypatch
fixture shared between testfunc and fixture func
#981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The problem persists on |
As a workaround, I think I will create a new fixture called |
The current behaviour is definitely unfortunate in this case, but intended - fixtures have a given scope ( I'm not sure what a good solution would be for this kind of thing - maybe having a new Let's see if someone else can come up with a better solution. |
While a unique scope might be a nice idea, I do not think calling monkeypatch.undo() manually is something that should be done. The whole purpose of the monkeypatch fixture is so that undo gets called automatically. It seems what this usecase wants is a context manager for the cwd (which pathlib in py3 might provide?). I'd rather close this issue as I don't think its a use case for a unique scope and what's described here is indeed as intended. If there is a good use case for a unique scope then feel free to open a different issue requesting it. Thanks |
I found it surprising that calling I guess I'll open an issue requesting a new scope if I ever actually need to undo a change to |
Note that calling `undo()` is generally not needed, and describe the "gotcha" discovered in pytest-dev#981.
@codewarior0 we once did brainstorming on more granular monkeypatch, it quickly turned into something incomprehensible due to more and more edge cases We want to retry in future, the main problem is finding a way to support their surroundings |
I wonder if the granularity could be done by making
|
Yes, the details are at stuff like yield fixtures I think we need a monkey patch manager fixture and a sub request scope, |
Occurs with py.test 2.7.2 on multiple platforms and Python versions.
I have a fixture function that uses monkeypatch to modify sys.path, and a test function that also uses monkeypatch to modify the cwd and then restore it to its old value. When
monkeypatch.undo()
is called in the test function, it undoes the changes done in the fixture function:Is there a way to get a different
monkeypatch
object in the test function?The text was updated successfully, but these errors were encountered: