Testing Infrastructure

The simpliest way to run tests is by using the ctest command. Check out the CMake page for further explanation.

Muscat comes with two ways of executing the automated tests. Remember that if not all the optional dependencies are installed some tests will fail. First, pytest [1] by simply executing in root directory of the library:

pytest

The files conftest.py and pytest.ini present at the root of the repository are responsible for the pytest configuration.

And the in-house testing tool using.

python -m Muscat.Helpers.Tests

This module searches all the modules recursively (in Muscat) and collectes all the functions named CheckIntegrity that take one boolean argument (True to generate output in the form of GUI to ease the manual debugging). The CheckIntegrity function returns the string "ok" if and only if the test was successful (or "skip" to ignore the test). Any other return value (or a raised exception) will be interpreted as a failed test.

Note

This tool can be used to test an installed version of Muscat to check the integrity of the installation on the final user environment.

The __init__.py must have a variable named _test listing all submodules to be tested so that the test infrastructure works as intended.

Some tests need to write data to disk or read data from the test data directory. Two functions are available to help writing tests :

  • GetTestDataPath() : Returns the path of the test data directory (from Muscat.TestData import GetTestDataPath )

  • TemporaryDirectory: A class to handle the creation of a directory to hold temporary data (from Muscat.Helpers.IO.TemporaryDirectory import TemporaryDirectory)

For more information about the options, use the command :

python -m Muscat.Helpers.Tests -h

Note

Some test will fail on some configuration Some packages are not available on all the supported platforms and some classes must be used inside a specific environments (paraview for example) The current know issues are :

Coverage

Coverage is an important part of the development process. To activate the coverage during test use the -c option.

If you want to tell coverage.py to ignore some part of the code, use the #pragma : no cover comment. For correct platform dependent coverage you can use the following comment to disconnect coverage in some platform:

# only nt coverage
# only posix coverage

See also [2].

Disabling Tests

Some tests can be disabled using an environment variable. A typical use case arises when a test relies on an external dependency that may not be available.

The feature relies on the definition of non-empty environment variables in the form : "XXXXX_NO_FAIL".

An example is available in the Muscat.Bridges.PyVistaBridge.CheckIntegrity() function.

Footnotes