OpenAssetIO
An abstract API for generalising interactions between a host application and an asset management system
openassetio.test.manager.harness Namespace Reference

A unittest based test harness that allows manager plugin developers to check that their implementation meets the requirements of the API. More...

Classes

class  FixtureAugmentedTestCase
 Base test case class that all test classes must inherit from. More...
 

Functions

def executeSuite (testSuiteModule, fixtures, unittestExtraArgs=None)
 Executes the supplied test suite with the given fixtures, optionally passing extra arguments to the underlying unittest framework. More...
 
def fixturesFromPyFile (path)
 Loads a fixtures dict from the specified python file. More...
 
def moduleFromFile (path)
 Loads a python module from the specified file, without it needing to be on PYTHONPATH. More...
 

Detailed Description

A unittest based test harness that allows manager plugin developers to check that their implementation meets the requirements of the API.

The harness can be invoked programatically or via tha CLI. The module exposes the main test entry point and fixture loading methods. This permits additional test suites to be written and run by the developer, to test manager-specific functionality if desired.

Function Documentation

def openassetio.test.manager.harness.executeSuite (   testSuiteModule,
  fixtures,
  unittestExtraArgs = None 
)

Executes the supplied test suite with the given fixtures, optionally passing extra arguments to the underlying unittest framework.

Parameters
testSuiteModulemodule A module of test cases deriving from FixtureAugmentedTestCase.
fixturesdict The fixtures corresponding to the supplied testSuiteModule.
unittestExtraArgsList[str] Additional args to pass to the unittest framework, see unittest.main argv for more details.
Returns
bool True if the suite passed, False if there was one or more failures.

The format of the fixtures dictionary is as follows:

1 fixtures = {
2  "identifier": <target manager plugin identifier>,
3  "settings": { <manager_setting>: <value> },
4  "shared": { "<fixture_name>": <value> },
5  "<Test_Case_name>": {
6  "shared": { "<fixture_name>": <value> },
7  "<Test_function_name>": {
8  "<fixture_name>": <value>,
9  ...
10  },
11  ...
12  },
13  ...
14 }

Where:

  • Test_Case_name: The name of a test class declaration within the supplied suite that derives from FixtureAugmentedTestCase.
  • Test_function_name: The the name of a test function defined within the named class.
  • fixture_name: The name of a fixture queried by the test function. This may be an input value, or an expected result.
  • shared: Fixtures values that will be inherited to inner classes or functions.

The test harness takes care of extracting the appropriate function sub-dictionary and making it available through self._fixtures.

NOTE: Fixture names need to be valid python variable names, and should only contain alpha-numeric characters and underscores.

def openassetio.test.manager.harness.fixturesFromPyFile (   path)

Loads a fixtures dict from the specified python file.

The supplied path should point to a python file defining a top-level fixtures variable holding a dict, populated with the required fixtures for the target test suite.

Parameters
pathstr The path to the file to load fixtures from.
Returns
dict The fixtures dict defined by the supplied file.
See also
executeSuite for details on the structure of the fixtures dictionary.
The manager template for a reference fixtures file.
def openassetio.test.manager.harness.moduleFromFile (   path)

Loads a python module from the specified file, without it needing to be on PYTHONPATH.

The file name is used as the module name. This can be useful to load test suites from files that are not otherwise on PYTHONPATH.

Parameters
pathstr The path to the file to load the module from.
Returns
The loaded module.