[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] unit and doc testing questions



On Tue, Jan 13, 2009 at 06:44:10AM -0600, Jake b wrote:
> I'm learning about doctest, and unittests. Now if I create a file, like
> pygame/test/rect_test.py , is there and easy way to import the project in
> its parent directory?

Make sure it's in sys.path, then import using the absolute package name.

(Hint: 'pygame' is a bad name for a project, it will clash with the
pygame library.)

> I thought "import ../mymodule" might work, ( but at least not in 2.5  ).
> Then I got it to work appending sys.path.

> 1) What is your advice on imports from test files? ( Do you append your
> sys.path, or something else? )

The test runner makes sure your project is importable by adding it to
sys.path, if necessary.

> 2) Do you have two seperate unittests ? (A) One is ran every time source
> files are compiled, and a second, (B) slower one is ran at a longer interval
> for slow tests ?

Such separation is rarely necessary.

I generally have a separate test module for every code module (with
separate tests for each function/method), and then a top-level script
that imports all test module, collects all the tests into a single
unittest.TestSuite, and runs them.  http://pypi.python.org/pypi/nose can
be used instead of a custom script, but I got used to writing those
before nose was available and so far hadn't gotten to try it out.

"Compiling" is a very nebulous, automatic and invisible step in Python.
I run the tests whenever I want to get some feedback on my code, and
also before committing my changes to the source control system (you have
one, right?)

> 3) Other advice relating to testing ?

Keep them short and fast.

Marius Gedminas
-- 
Microsoft has performed an illegal operation and will be shut down.
                -- Judge Jackson

Attachment: signature.asc
Description: Digital signature