Carel
Carel

Reputation: 3397

Including module structure for testing but not for distribution

Consider the following package structure

project   # Project root
 package  # Main package that one wants to distribute
  ...     # Modules comprising the package
 mockup   # Mock up of a package structure used for testing
  ...     # Modules comprising the mock up structure
 tests    # Testing package containing unittests
  ...     # Modules comprising the unittests
 setup.py # setup script

How should one configure the setup.py script to

Presently I have the following specified; which distinguishes the package code from the testing code but does not make the mockup available during test execution.

setup(
  ...
  package = find_packages(exclude=['tests','mockup']), # Includes package code but not tests or mockup folders
  test_suite ='tests',                                 # Includes tests but not the mockup's
  ...
)

Specifying mockup/** in MANIFEST.in includes it in the distribution as does specifying package_data/include_package_data in setup.py. Perhaps Tox allows mockup structures but I'm not finding this in the documentation.

Upvotes: 1

Views: 268

Answers (1)

Oliver Bestwalter
Oliver Bestwalter

Reputation: 5397

tox builds a package exactly like it is specified in setup.py and MANIFEST.in by running python setup.py sdist for you. There is no way to build a special package for testing with tox. This would defeat the purpose of tox, which is that you test exactly the package that you want to release.

If you want to run some special tests with files/folders that should not be part of the release, but which are part of the project (so part of the project structure in which your tox.ini lives) I would recommend to run those tests against a development install of your project, which contains all you need. You should still test the package against your other tests, but those other tests could be done in a different tox environment.

Very simplified, in a project that contains the different test types in different folders under tests this could look something like that (I am writing this from a pytest user perspective - you will have to translate that to unittest - or just run your unittests like this with pytest :)):

[tox]
envlist = tests,mockuptests

[testenv:tests]
description = runs the "normal" tests against the installed package
deps = pytest
commands = pytest tests/normal

[testenv:mockuptests]
description = runs the "mockup" tests against an editable installation
usedevelop = True
deps = pytest
commands = pytest tests/mockup

On second thought I think that testing the package against the mockups should also be possible in a different way without having to put those files into the package, depending on how your tests are structured and how your testrunner does stuff. As run unittest and I don't have enough details about your project setup, I don't know how you would do this in your case.

Upvotes: 2

Related Questions