PySpec Usage Guide
||yoshiki at shibu.jp
||This document has been placed in the public domain.
Write and Run Specs
In PySpec, the specification is represented in python function or method.
These specification methods have special decorator.
# This is function style spec
# This is method style spec
If you want to share any objects between specifications and contexts
(context is a setup method), you should write specs in class. PySpec
creates one object per one spec. It doesn't pollute other test environment.
PySpec searches specs from top level functions and classes. If you write
specs in nested class, that will not be called.
Running Specs on Console
You have two ways to run console runner. First way is
Another is writing startup code into your spec source files. It's easy.
from pyspec import *
# Define some specs here
if __name__ == "__main__":
You don't have to register your specs. PySpec searches all modules that are
loaded in your interpreter automatically. So, this code can kick specs in
If you want to run all specs that are divided into some files, creating
startup script is the easiest.
from pyspec import*
If you have created a spec startup script file and added startup code into all
your specs, you would be able to all tests and each test.
Running Specs on GUI
You can use GUI runner too. Run wxpyspec.py
script. You can load spec module file
from [Project] - [Add module...]
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
||Now I rebuilding GUI runner. There are some bugs and not fixed.</td>
If you want to run GUI startup code from your spec script, please add
if __name__ == "__main__":
controller = pyspec.wxui.controller.WxPySpecController(0)
The spec which have good name is good spec. In pyspec, you have 2 ways to set the name.
These spec names will appear in the result report.
Using method name is more simple way.
||A stack which have one value
||versioninfo in sys module
||one of testmethod should fail
This feature is implemented in pyspec.util.createspec
Docstring is used for the spec names. Python 2.X can accept ASCII names only as a method name.
This function is for programmers in Asia.
If you write docstring in context method and spec method, the first line of docstring
is used as a spec name.
PySpec gets docstring encoding from the first line of source code. If you want to use
Japanese or Chinese or any languages, you should write as following:
# -*- coding: utf8 -*-
Pyspec can accept any codec which is installed in python.
"""Youso wo hitotsu motsu stack."""
self.stack = Stack()
"""kara dewa nai."""
Youso wo hitotsu motsu stack
kara dewa nai ... OK
This sample docstrings are Japanese pronunciation in English.
Of course, you can write real Japanese.