Search code examples
pythonpackaging

How to publish my unit tests with my python package


How can I publish my tests along with my package? I want to keep my tests separate from src, as below.

mypackage/
    src/
        mypackage/
            __init__.py
            hello.py
    tests/
        test_hello.py

And the content of my setup.cfg is:

[metadata]
name = mypackage
version = 1.5.0
author = John Henckel
url = https://test.com
[options]
package_dir =
    = src
packages = find:
[options.packages.find]
where = src

However when I do build + twine the tests are not included. Is there a way to include the tests in the tar and wheel?


Solution

  • It appears people put the tests/ folder inside the module directory when they want to distribute them along with the code.

    Related SO question.

    You can see the project structure they use here.

    Edit: This link suggests that you just have to list the directories in your setup.py

        packages=['an_example_pypi_project', 'tests'],
    

    I cannot find anything about setup.cfg though I would imagine it should be the same.