Skip to main content

unit test generator for Python

Project description


Easiest way to get Pythoscope is via setuptools:

$ easy_install pythoscope

You can also download a source package from–files/download/pythoscope-0.4.3.tar.gz or get a copy of a development branch using bazaar:

$ bzr branch lp:pythoscope

To install the package from the source directory do:

$ python install

You don’t need setuptools for this to work, a bare Python will do just fine.

However, if you do have setuptools installed, you may also consider running the whole test suite of Pythoscope:

$ python test


You can use the tool through a single pythoscope command. To prepare your project for use with Pythoscope, type:

$ pythoscope --init path/to/your/project/

It’s only doing static analysis, and doesn’t import your modules or execute your code in any way, so you’re perfectly safe to run it on anything you want. After that, a directory named .pythoscope will be created in the current directory. To generate test stubs based on your project, select files you want to generate tests for:

$ pythoscope  path/to/your/project/specific/  path/to/your/project/other/*.py

Test files will be saved to your test directory, if you have one, or into a new tests/ directory otherwise. Test cases are aggregated into TestCase classes. Currently each production class and each production function gets its own TestCase class.

Some of the classes and functions are ignored by the generator - all which name begins with an underscore, exception classes, and some others.

Generator itself is configurable to some extent, see:

$ pythoscope --help

for more information on available options.

Editor Integration


We put out an elisp script that integrates Pythoscope into Emacs. The file is in the the misc/ directory of the source distribution. You can also look at the file on Launchpad. Usage and installation instructions are in the comments at the top of the file.


There is interest in Vim integration and someone is working on it but we have nothing for you right now.


There was much discussion of Leo on the mail list editor integration thread.


All Pythoscope source code is licensed under an MIT license (see LICENSE file). All files under lib2to3/ are licensed under PSF license.



  • Pythoscope now ignores application and test modules it could not inspect (#487138 #462849).

  • Improved generation of assertions for functions with varargs and kwargs (#475414 #475409).

  • Pythoscope will no longer generate two test cases with the same name (#475504).

  • Installation package now contains all essential files (#481238).

  • Pythoscope now properly handles string exceptions thrown inside entry points (#522364).

  • Entry points are now run with the current directory being the project root (#524352).



  • Greatly improved information storage performance.

  • Added Pythoscope module for Emacs to the misc/ directory in the source tree.

  • Unittests can now be used as points of entry (#275059).

  • Pythoscope now ignores source control files (#284568).

  • Static inspection happens on –init, as it should be (#325928).

  • Ported itertive pattern matcher for lib2to3 from Python trunk (#304541).

  • Fixed test generation bug related to nested function arguments (#344220).

  • Fixed point of entry cleanup bug (#324522).

  • Fixed some more Windows-specific bugs (#348136).





  • Fixed generate bug for test modules (#264449).

  • .pythoscope became a directory.

  • Introduced –init option for initializing .pythoscope/ directory.

  • Added a notion of points of entry introducing dynamic analysis.

  • Pythoscope can now generate assert_equal and assert_raises type of assertions.

  • Implemented no more inspect command blueprint.

  • Changed the default test directory from pythoscope-tests/ to tests/.

  • Added a tutorial to the README file.


  • Fixed the inner classes bug (#260924).

  • Collector appends new data to .pythoscope file instead of overwriting it.

  • Test modules are being analyzed as well.

  • Using lib2to3 for static code analysis instead of stdlib’s compiler module.

  • Generator can append test cases to existing test modules. Preserves comments and original whitespace.

  • Cheetah is no longer a dependency.

  • Renamed ‘collect’ command to ‘inspect’.


Contains a packaging bug fix, which prevented users from using the tests cases generator and running internal pythoscope tests.


First release, featuring static code analysis and generation of test stubs.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pythoscope-0.4.3.tar.gz (112.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page