Development/Python Unit Tests

This page explains the Python tests used inside of LibreOffice code. The Python based UI tests are documented on their own page.

Getting started
Python unit tests are seamlessly supported al least in the following modules : dbaccess pyuno sw sc solenv sfx2 (You can get an up-to-date list with )

Create an unit test
In the following, the paths are given relative to the folder containing LibreOffice sources.

Create
Example:

Note:  For  tests, use instead

Add the test to
Example:

Note:  For  tests, use instead

For new modules
If no python unit test is defined for a module, you should create  and   as explained avobe. Then, add your test to.

Example:

Note:  the tests defined in this way are running during subsequentcheck phase (also on Tinderboxes that activated it).

All tests of a module
Examples:

OpenSUSE
Note: debug repo must be activated (in yast)

Until we have this hook up and running in upstream python:

put this in your unit test (sw/qa/unoapi/python/get_expression.py):

Run the test:

(gdb) run

Source the gdb python extension (needed only on OpenSUSE):

(gdb) source /usr/share/gdb/python/gdb/libpython.py

and run

(gdb) py-list

Debug python unit test on Windows
As always life on Windows is different. Debugging python unit tests is not an exception here. To debug, just put a sleep time in your python code, make sure it is say 60 seconds (If you are mst__ then 10 may be enough ;-)

In meantime go to MSVS and attach the debugger to python process. Be warned, that there are two python processes, wrapper and the C Python process. Obviously you need the C Python one. Once the debugger is attached, click suspend button to suspend the process execution, otherwise it just continues.

Defining env var in make file and using it in test
An env variable can be defined in make file with `gb_PythonTest_set_defs` method. For example to define a directory to load test documents from:

Framework's `uno.openWriterTemplateDoc` method can load the test documents from the directory above:

The function can be used:

Additional links

 * Python Unit testing framework
 * gdb Support
 * Python Debugging Tipps
 * gdb libpython
 * - Closed
 * Auto loading python module
 * Auto loading python module