Testing - Amourspirit/live-libreoffice-python GitHub Wiki
Table of Contents
Overview
Testing is done using pytest.
Test can be run on the command line.
To run the tests, simply run pytest
in the root directory of the project.
Test can also be run in Visual Studio Code.
Creating Tests
Tests are created in the tests
directory. The test that are there are just examples and can be removed in you project.
It is recommended to create a __init__.py
file in the tests
directory, also create a __init__.py
file in each sub directory of the tests
directory. This will allow the test be be treated as a package and sub-packages for pytest.
This has the advantage of allowing to use the same test names in different sub directories.
Starting LibreOffice
When a test is run you have to option to start LibreOffice manually before your test or have OooDev handle starting and stopping LibreOffice for you. In the included test examples, LibreOffice is started and stopped automatically.
The loader
fixture (using OooDev) is used to start and stop LibreOffice. The loader
fixture is used in the conftest.py
file in the tests
directory. Generally speaking you should not have to change this file.
Test Configuration
Test can be run without any extra configuration. By default the test will run in headless mode. This means that LibreOffice will not be visible when the test are running.
A .env
file can be created in the root directory of the project to configure the test.
Default Configuration:
TEST_HEADLESS=1
TEST_CONN_SOCKET=1
TEST_CONN_PORT=2002
TEST_CONN_SOCKET_HOST=localhost
TEST_CONN_SOCKET_KIND=default
TEST_HEADLESS
If TEST_HEADLESS
is set to 0
then LibreOffice will be visible when the test are running.
TEST_CONN_SOCKET
If TEST_CONN_SOCKET
is set to 0
then the test will create a pipe connection to LibreOffice and use that to run the test; Otherwise, the test will use the default connection which is via a host and port.
TEST_CONN_PORT
This is the port that is used to connect to LibreOffice. The default is 2002
. Not recommended to change this.
TEST_CONN_SOCKET_HOST
This is the host that is used to connect to LibreOffice. The default is localhost
. Not recommended to change this.
TEST_CONN_SOCKET_KIND
This is the kind of connection that is used to connect to LibreOffice. The default is default
.
Setting this value to no_start
will not start LibreOffice if it is not already running.
Other Resources
- OooDev Tests has a large number of tests that can be used as examples.
- The OooDev docs are a great resource for working with LibreOffice and Python.
- The ScriptForge Library libraries build up an extensible collection of macro scripting resources for LibreOffice to be invoked from Basic macros or Python scripts.
- pytest for more information on how to use pytest.