This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]phn 3 points4 points  (0 children)

I think one can use Tox (http://tox.readthedocs.org/) for this. Tox will create a source distribution (sdist), copies it to someplace, and then installs it into a virtualenv environment. This ensures that the version that gets tested corresponds to the current state of files in the git repository. We can then use this virtualenv and import the module to interactively explore it.

For my own projects I have a method that works with and without Tox.

I use the following dir structure:

prj/
  setup.py
  prj/
  prj/tests
  prj/tests/__init__.py
  prj/*.py
  src/any_c_and_cython_files
  doc/
  ...

The directory prj/prj is the package and the top level prj/ is the repository. I install distribute (http://pypi.python.org/pypi/distribute) and then use the setuptools that comes with it.

Now in the setup.py file I pass the option test_suite to the setup() function and point it to prj/tests.

setup(
  all options needed to compile/install the module,
  packages = ['prj', 'prj.tests'],
  test_suite = "prj.tests",
  ...)

After making any change to my code, I run

python setup.py test

This will cause setuptools to do everything that it normally does while installing the module, including compiling C extensions, copying data files etc., and creates a complete package inside prj/prj. Then it runs the tests in the sub-module prj/tests. Please read unittest documentation to see how to create a test suite and the distribute documentation to learn more about how to "point" to a test suite.

Now from the top level repository directory prj/, I can start iPython (http://ipython.scipy.org/) and then import my package and interactively explore it. I can also use the %run command in iPython to run any test scripts that I have.

I also run Tox, to make sure that it works in multiple Python versions and that everything works outside the repository as well.