-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
monkeypatch does not work on already-imported function #603
Comments
Original comment by Marco Chomut (BitBucket: Pewpewarrows, GitHub: Pewpewarrows): The documentation disagrees: "For convenience you can specify a string as target which will be interpreted as a dotted import path, with the last part being the attribute name." |
Original comment by Anatoly Bubenkov (BitBucket: bubenkoff, GitHub: bubenkoff): oops, sorry, didn't know we support also that :) |
Original comment by Marco Chomut (BitBucket: Pewpewarrows, GitHub: Pewpewarrows): Oh interesting, and that makes sense now that you pointed it out. If I change the patching line to:
then everything works as intended. It seems that monkeypatch is working as intended then, sorry for the ticket. I suppose some documentation on this particular piece of behavior might be useful. |
Originally reported by: Marco Chomut (BitBucket: Pewpewarrows, GitHub: Pewpewarrows)
Given the following tests file:
And this system under test:
Then the
zoo
that's already been imported inmain.py
remains unpatched. Moving the imports around to be local to the test function would fix the problem, unlessmain.py
is imported by other files at any point during the test suite running. Alternatively, ifmain.py
instead doesimport project.bar
and calls its dependency withproject.bar.zoo('lion')
, then the test passes again. But this is cumbersome and difficult to enforce across an entire project.The text was updated successfully, but these errors were encountered: