[py-dev] How can I use py.test in trytond

Nicolas Évrard nicoe at no-log.org
Mon Apr 4 13:03:24 CEST 2011


* holger krekel  [2011-04-04 09:37 +0200]: 
>Hi Nicolas,

Hello,

>> Currently I use a conftest.py file in the top directory in order to
>> define funcargs for my tests. But it looks like a suboptimal solution.
>>
>> I think I can use plugins in order to do the following:
>>
>>      1. Define a funcarg `sale` in the sale module
>>      2. Define a funcarg `sale` in the sale_cost module. This funcarg
>>         should ideally use the funcarg from `sale` and extend it with
>>         various information (if allowed to do so by the business rule).
>>      3. Calling py.test trytond/modules/sale_cost from the project/
>>         directory should work
>>
>> This setup would allow me to provide funcargs for use to other
>> developers on which they can base their own tests.
>>
>> Right now I noticed that the funcargs are loaded recursively. Do you
>> think it is possible to write a plugin that would read the dependency
>> information in the sale_cost module and use it to setup the conftests
>> file found in those modules to be imported *before* the conftest.py
>> from sale_cost ?
>>
>> If it is, do you have any pointers on how I can do this ?
>
>request.getfuncargvalue() can be called to decorate an existing funcarg,
>see http://bit.ly/eiByLF

Thank you for the link I missed it while going through the doc
(although I knew that you could call getfuncargvalue to get the
'previous' value and play with it).

>However, i guess you could just have a single conftest.py which provides different
>values for your funcargs depending on which directory they are requested from.

That's precisely what I don't want to do.
Because modules are distributed through pypi and thus you never know
which modules are installed. Moreover, I think that such a setup would
have many difficulties to address all the possible cases (modules
incompatibilities, bad dependency specified in the __tryton__ file,
and so on).

My idea is the following:

     - During test conftest collection, locate the nearest
       __tryton__.py file (by going in the direction of the root of the
       file system).
     - Once you found it, collect also conftest information from
       the modules specified in this file (the modules are usually in a
       sibling directory from the directory where you found the
       __tryton__.py file but they may also be found thanks to their
       entry point).
     - The collection should of course work recursively

It is important not to load all conftest information (because one
might have conflicting configuration for the same object) but only the
one you depend on.

Is this kind of setup doable in a plugin ?
Am I completely wrong about how this problematic should be addressed ?

>> BTW, py.test is a really nice piece of software and I really enjoy
>> using it.
>
>BTW, nice to hear :)

It is well deserved :).

-- 
(°> Nicolas Évrard
( ) Liège
  `¯



More information about the Pytest-dev mailing list