2

I want to create a python package, but I am not sure what the best place for the unittest directory is. In the Hitchhikers Guide the tests are put inside the actual module, as well as here, while the Python Project HowTo advocates putting them in an extra directory on project level.

So should the project be layed out as this (Format A):

MyProject/
  |-- setup.py
  |-- README
  |-- mypackage/
       |-- __init__.py
       |-- some_module.py
       |-- test/
            |-- __init__.py
            |-- test_module.py
  |-- scripts/
       |-- script1.py

or like this (Format B):

MyProject/
  |-- setup.py
  |-- README
  |-- mypackage/
       |-- __init__.py
       |-- some_module.py
  |-- test/
       |-- __init__.py
       |-- test_module.py
  |-- scripts/
       |-- script1.py

What are the advantages/disadvantages in either case? Is this defined somewhere?

I want to use distutils(2) for the packaging (setup.py and/or setup.cfg) so it could be especially important under these circumstances how to structure the tests. In Format A the unittests will be included automaticaly in the package (if the package as a whole is defined) while for Format B the unittests must be specified in a separate way (which I even do not know).

Alex
  • 41,580
  • 88
  • 260
  • 469
  • 2
    There are a lot of opinions on where to put tests, check this thread http://stackoverflow.com/questions/61151/where-do-the-python-unit-tests-go. – alecxe Jul 22 '13 at 09:01
  • The page you linked is not too helpful and 5 years old. Maybe there are newer opinions, or even newer regulations/conventions/PEPs available... – Alex Jul 22 '13 at 09:16

0 Answers0