[pytest-dev] Working with other dependency injection systems
holger krekel
holger at merlinux.eu
Thu May 7 13:21:07 CEST 2015
Hi Kai,
On Thu, Apr 30, 2015 at 19:28 -0400, Kai Groner wrote:
> Hi testing people!
>
> I'm trying to figure out how I can test a code base that uses an existing
> dependency injection system. I've run into two problems, and I have
> solutions for each of them but I think maybe there is a better way, so I'm
> looking for some advice.
Could you provide a simple abstract example?
Here and also in the following i don't really understand the background.
holger
> The first problem is how do I override how a test using this injector is
> called? I think I want to use the pytest_runtest_call hook, but it still
> tries to invoke the test without the injector. My current solution is to
> use the experimental hookwrapper mechanism to replace item.obj with a
> partially bound version, then restore it afterward.
>
> The second problem I'm having is the py.test fixture system is trying to
> resolve arguments that are provided by this other injector. How can I tell
> it that some of these don't need to be provided? My current solution is to
> blind py.test with a wrapper function with a *a, **kw signature. I use
> functools.wraps, so annotations are introspectable for the other injector,
> and delete the __wrapped__ attribute to prevent py.test from introspecting
> it. Is there a nicer, and perhaps less blunt, way to influence the funcarg
> fixture behaviors? I've tried a couple things with the
> pytest_collection_modifyitems hook, but haven't gotten anything that works
> yet.
>
> Other details to know about this injection system:
> - we want to build and teardown the injector with each test
> - we may want to configure the injector differently for some tests
> (possibly with fixture data from py.test)
>
>
>
> Thanks,
> Kai
> _______________________________________________
> pytest-dev mailing list
> pytest-dev at python.org
> https://mail.python.org/mailman/listinfo/pytest-dev
--
about me: http://holgerkrekel.net/about-me/
contracting: http://merlinux.eu
More information about the pytest-dev
mailing list