-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
magic handling of mock.patch() is confusing and not generic enough. #2828
Comments
the correct way forward is to find a signature and use it - #2267 should be a way forward then the other decorators just have to fix the signature |
How will The wrappers just take My suggestion would be to allow This approach has worked really well for me with another dependency injection project here, where implicit dependency injection based on argument name is only used as a fallback: http://mush.readthedocs.io/en/latest/use.html#declarative-configuration |
the correct way for functions to change a signature is to set a new one, now mock doesn't do that already, and im inclined to go ahead and start to warn about this so that all tests that are detected as wrapepers will be warned about id much prefer direct injection in all cases (aka involve pytest machiery) as well as getting the fixture mechanism to be more a library and less a pytest only hell that cant be reused |
How does a library set a new signature in a graceful way that supports both Py2 and Py3? I'd prefer no more warnings that end users who will see them can't easily do anything about... Not sure what you mean by 'direct injection in all cases'? I'm planning to pivot mush somewhat such that it's primary use will be: from mush import Context, requires
context = Context()
def my_func(the_thing):
...
context.add(SomeThing(), returns='the_thing')
context.call(my_func)
# or:
context.call(my_func, requires='the_thing')
# or instead define the function as one of the following:
@requires('the_thing')
def my_func(another_name):
...
def my_func(another_name: 'the_thing'):
...
def my_func(another_name: SomeThing):
... Would that be of use/interest? |
@cjw296 wrt setting signatures for all python version, use funcsigs, pytest will, too wrt dependency injection in pytest - the injector needs to support life-cycle management and nesting of livecycles, so the mush example cant help us, at the backend we have scopes and scoped parameters as dependency and would like to control tear-down of them and their dependencies, we should probably open a new issue for that discussion |
How do you use funcsigs to set a new signature? (hopefully that's a silly question with an easy answer!) For the dependency injection, yes, either ping me an email or open a new ticket and CC me in. I suspect Mush already does a bunch of the needed stuff (providing a registry of dependencies and a nice interface for looking them up, layering lifecycles and scoping over that may be something that can sensibly be added, or could just be something that lives elsewhere but uses the stuff that Mush does do...) |
@cjw296 signatures are set on a wrapper by adding a signature object |
Is this fixed by #2842? |
@nicoddemus no, because the libraries in question also must use the mechanism to annotate |
@nicoddemus @RonnyPfannschmidt - what is the mechanism in question? I'd happily do the necessary in testfixtures, just as long as it's not a special case hack for pytest. |
@cjw296 the required mechanism needs to set a however mock is broken in many python versions and part of the stdlib, so we will have to deal with its mess forever |
Is ps: you at PyConUK? |
https://www.python.org/dev/peps/pep-0362/ - in particular https://www.python.org/dev/peps/pep-0362/#visualizing-callable-objects-signature im not at PyConUK - i wont be at conferences until the kid is able to walk |
Ah cool, I'm more than happy to do that for the testfixtures stuff... |
We are following the PEP already and |
@nicoddemus - sorry, just to confirm: current releases of pytest will respect a |
AFAIU yes, by using |
Oh and that will be available in pytest 3.3+, which we plan to release in the next couple of weeks. |
Can we leave this open until 3.3 is released? I hope you're duck typing whatever's in |
we use funcsigs to create/manipulate the objects and if you want to implement the same api, good luck with the minor details across python versions |
based on https://github.com/pytest-dev/pytest/pull/2842/files you will face massive trouble if you dont match the constants |
Yeah, unless your comments about |
@cjw296 the constants need to be addressed - i#ll make a critical issue blocking the release |
Is this still an issue? It is marked as "Need information", what information is missing? |
I think from a pytest perspective, this can be closed. |
Okay, so I'm raising this as a result of:
simplistix/testfixtures#65
testfixtures'
log_capture()
(and a couple of other decorators it offers) use the same pattern asmock.patch
as implemented here:https://github.com/Simplistix/testfixtures/blob/efc8082211e1c462aea23307d4ff4788e582bdce/testfixtures/utils.py#L24
However, I see that
mock.patch
only works because of the magical handling here:pytest/_pytest/compat.py
Line 74 in 46e3043
This means that end users and library developers are confused when one works and not the other does not. Not sure I have any good suggestions, just wanted to vent over the hours I've wasted on this...
The text was updated successfully, but these errors were encountered: