[TIP] Advice on location of tests modules

Olemis Lang olemis at gmail.com
Thu Feb 27 13:43:05 PST 2014


Recently a discussion has started about the location of test modules
developed for Apache Bloodhound [1]_ . In its current form the code in
/trunk includes three approaches :

  1. Our modified copy of Trac includes multiple test modules
     i.e. one source code per-package all over across the whole hierarchy
  2. A single sub-module tests as a child of the source code top-level
package
      e.g. bhdashboard.tests , bhsearch.tests , bhrelations.tests , ...
  3. A separate top-level module for unit + functional tests in Bloodhound
      Multiproduct plugin .

I'd rather prefer the option (3) because of the reasons I mentioned in
bh:comment:3:ticket:770 [2]_ which I repeat below :

  - Having a single top-level tests module (as opposite to Trac's
    scattered test modules)
    is convenient considering the package test discovery code
    * it's not unittest package discovery but our own code relying
      on setuptools (or equivalent) + pkg_resources
  - For code with functional + unit tests (i.e. quite often) I prefer to
    write tests in a separate package hierarchy because :
    * they should not be installed in production deployments
    * they might be packaged and distributed independently should they be
      run upon a given source tree to identify a certain issue , but then
discarded
    * in practice there might be no need to import top-level source tree
      in order to import top-level test module and contained test code
especially if
      writing functional tests
      - you'll need other dependencies instead e.g. [pypi:selenium] ,
        [pypi:twill] , stdlid `xmlrpclib` ...
      - and even for unit tests the top-level source package may always be
        imported and resources located with the help of `pkg_resources`

.. [1] https://issues.apache.org/bloodhound/ticket/770

.. [2] https://issues.apache.org/bloodhound/ticket/770#comment:3

I found other references on the subject

.. [3]
https://pytest.org/latest/goodpractises.html#choosing-a-test-layout-import-rules

.. [4]
http://stackoverflow.com/questions/5341006/where-should-i-put-tests-when-packaging-python-modules

.. [5]
http://stackoverflow.com/questions/61151/where-do-the-python-unit-tests-go

... but I'd like to know what's your opinion . All other recommendations
based on previous experience will be welcome as well

Thanks in advance !

-- 
Regards,

Olemis - @olemislc

Apache(tm) Bloodhound contributor
http://issues.apache.org/bloodhound
http://blood-hound.net

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140227/b50b28b1/attachment.htm>


More information about the testing-in-python mailing list