unit test generator for Python
Easiest way to get Pythoscope is via setuptools:
$ easy_install pythoscope
You can also download a source package from http://pythoscope.org/local–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 setup.py 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 setup.py 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/file.py 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.
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).
- Removed dependency on fixture module.
- Fixed test generation bug related to function definitions with varargs (#440773).
- Dynamic inspector can now handle all types of exceptions (including string exceptions).
- Frequently Asked Questions document has been created, also available online.
- Added support for Pythons 2.3 through 2.6.
- New imports added by Pythoscope are now placed after existing ones, so they don’t cause a syntax error when __future__ imports were used (#373978).
- Fixed inspection bug related to classes deriving from namedtuple instances (#460715).
- Setuptools is no longer required for installation.
- 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).
- Stopped using pickle for object serialization and implemented our own mechanism that carefully captures changing state of objects during dynamic inspection.
- Implemented preserve objects identity blueprint.
- Fixed bug related to multiple generator calls (#295340).
- Made handling of special method names (like __init__ or __eq__) consistent with handling of normal method names.
- Made test stubs more useful.
- 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.