pysys.config.project

The Project class holds the pysysproject.xml project configuration, including all user-defined project properties.

Project

class pysys.config.project.Project(root, projectFile, outdir=None)[source]

Bases: object

Contains settings for the entire test project, as defined by the pysysproject.xml project configuration file; see Project Configuration.

To get a reference to the current Project instance, use the pysys.basetest.BaseTest.project (or pysys.process.user.ProcessUser.project) field.

All project properties are strings. If you need to get a project property value that’s a a bool/int/float/list it is recommended to use getProperty() which will automatically perform the conversion. For string properties you can just use project.propName or project.properties['propName'].

Variables
  • ~.properties (dict(str,str)) – The resolved values of all project properties defined in the configuration file. In addition, each of these is set as an attribute onto the Project instance itself.

  • ~.root (str) – Full path to the project root directory, as specified by the first PySys project file encountered when walking up the directory tree from the start directory. If no project file was found, this is just the start directory PySys was run from.

  • ~.projectFile (str) – Full path to the project file.

expandProperties(value)[source]

Expand any ${…} project properties in the specified string.

An exception is thrown if any property is missing. This method is only for expanding project properties and ${eval:xxx}) strings, so ${env.*} syntax is not permitted (if you need to use an environment variable, put it into a project property first).

New in version 1.6.0.

Parameters

value (str) – The string in which any properties will be expanded. ${$} can be used for escaping a literal $ if needed.

Return str

The value with properties expanded, or None if value=None.

getProperty(key, default)[source]

Get the specified project property value, or a default if it is not defined, with type conversion from string to int/float/bool/list[str] (matching the default’s type; for list[str], comma-separated input is assumed).

New in version 1.6.0.

Parameters
  • key (str) – The name of the property.

  • default (bool/int/float/str/list[str]) – The default value to return if the property is not set. The type of the default parameter will be used to convert the property value from a string if it is provided. An exception will be raised if the value is non-empty but cannot be converted to the indicated type.

static getInstance()[source]

Provides access to the singleton instance of Project.

Raises an exception if the project has not yet been loaded.

Use self.project to get access to the project instance where possible, for example from a pysys.basetest.BaseTest or pysys.baserunner.BaseRunner class. This attribute is for use in internal functions and classes that do not have a self.project.

static findAndLoadProject(startdir=None, outdir=None)[source]

Find and load a project file, starting from the specified directory.

If this fails an error is logged and the process is terminated.

The method walks up the directory tree from the supplied path until the PySys project file is found. The location of the project file defines the project root location. The contents of the project file determine project specific constants as specified by property elements in the xml project file.

To ensure that all loaded modules have a pre-initialised projects instance, any launching application should first import the loadproject file, and then make a call to it prior to importing all names within the constants module.

Parameters
  • rstartdir (st) – The initial path to start from when trying to locate the project file

  • outdir (str) – The output directory specified on the command line. Some project properties may depend on this.

getProjectConfigTemplates

pysys.config.project.getProjectConfigTemplates()[source]

Get a list of available templates that can be used for creating a new project configuration.

Returns

A dict, where each value is an absolute path to an XML template file and each key is the display name for that template.

createProjectConfig

pysys.config.project.createProjectConfig(targetdir, templatepath=None)[source]

Create a new project configuration file in the specified targetdir.