SampleTest

class ip_manager.testing.SampleTest

Easily configure which sample files to automatically test with pytest.

This pytest class allows to configure a list of paths to sample files that need to be run during testing so that it is automatically and continuously verified that the samples work.

To use this functionality, write a test class and inherit from SampleTest. Override the sample_src method and have it return a list of paths. A path can be absolute or relative and can either point to a specific file or a directory. When providing a path to a directory, all sample files matching the default sample expression will be executed in this directory and its subdirectories recursively. Marks (pytest.mark) can be added for specific sample files to provide further configuration information to pytest. To assign one or more marks to one or more sample files add them to the list as a tuple containing all the required marks and all sample files on which to apply these marks.

Optionally, the method work_dir can be overridden to return an absolute path to the working directory. Relative paths in sample_src are resolved with this working directory. By default the working directory is set to the directory of the current test file.

The discovery of sample files in directories includes files to the test set when their filename matches any of the following expressions:

  • sample_*.py

  • example_*.py

  • execute*.py

  • plot_*.py

  • explore_*.py

Examples

# Example of how to setup tests for sample files in multiple locations.

from ip_manager.testing import SampleTest
from os.path import abspath, join, dirname, pardir
import pytest

class TestLibrarySamples(SampleTest):
    def work_dir(self):
        return abspath(join(dirname(__file__), pardir))

    def sample_src(self):
        return [
            "team_library/ipkiss/team_library/components/",
            ("docs/sample_circuit_simulation.py", pytest.mark.skip(reason="Long simulation")),
        ]
sample_src()

List of relative or absolute paths to sample files or directories. Marks are added to samples by combining the marks and the sample paths in a tuple.

Returns:
list
work_dir()

Absolute path of the working directory. Overriding this method is optional.

Returns:
str