polyspace.project.Project Class
Namespace: polyspace.project
Description
Create or load a Polyspace® Platform project and manage the project configuration using this Python® class.
Creation
Description
proj = polyspace.project.Project("myProjectName") loads the project from the file myProjectName.psprjx, if it already exists, or creates a new project in the current folder. You use the object proj to manage the project configuration. You do not need to specify the file extension (.psprjx) when you create or load a project file. If you create a new project, the project file
myProjectName.psprjx is not saved to your file system until you explicitly run the proj.save() command.
Properties
Basic Information
Full path to project file (.psrpjx) including project name, specified as a string.
Example: r"C:\Polyspace_Projects\newProject.psprjx"
Name of project author, specified as a string. For more information on the corresponding configuration option, see Author.
Example: "matt"
Version identifier to indicate the current state of the project, specified as a string. This identifier appears in reports generated from test or profiling results. For more information on the corresponding configuration option, see Version.
Example: "1.0"
Example: "1.1.23 (stable)"
Date and time when project was created, specified as a datetime.datetime object. For more information on the corresponding configuration option, see Created.
Example: 2024-Jul-17 14:14:14
Date and time when the project was last saved with modifications, specified as a datetime.datetime object. For more information on the corresponding configuration option, see Last modified.
Example: 2024-Jul-17 14:14:14
Descriptive information about the project, specified as a string.
Example: "This is my test project."
Configuration
Build configurations owned by the project, returned as a polyspace.project.BuildConfigurationList object. A polyspace.project.BuildConfigurationList object is a list of polyspace.project.OwnedBuildConfiguration objects. The object properties correspond to the build-related options in Polyspace
Test™. See Test Execution in Polyspace Platform User Interface.
This table summarizes the ways you can use a build configuration that is owned by a project proj.
| Action | Command |
|---|---|
| Create new owned build configuration | ownedBuildConfig = proj.BuildConfigurations.create("myBuildConfig") |
| Load existing configuration | ownedBuildConfig = proj.BuildConfigurations["Owned config name"] |
| Create owned build configuration by copying an existing build configuration |
Here,
Optionally, use the |
| Convert a referenced external build configuration to an owned build configuration |
Here, |
Export a copy of an owned build configuration object to a .pscfg file | ownedBuildConfig.export("filename.pscfg") |
| View available build configurations owned by the project | proj.BuildConfigurations |
| Modify a property of an owned build configuration | ownedBuildConfig.Libraries.append("gtest.lib") |
| Display owned build configuration | Quiet — Verbose — |
| Set the active build configuration for the project | proj.ActiveBuildConfiguration = ownedBuildConfig |
Since R2026a
External build configurations referenced by the project, returned as a polyspace.project.BuildConfigurationRefList object. A polyspace.project.BuildConfigurationRefList object is a list of polyspace.project.BuildConfigurationRef objects.
This table summarizes the ways you can interact with build configurations referenced by the project proj:
| Action | Command |
|---|---|
| Add a reference to an existing external build configuration |
You can provide a full or relative path to the external configuration file. Relative paths are considered relative to the location of the project. |
| Convert an owned build configuration to an external configuration, referenced by the project |
Here, |
| Remove a reference to an external build configuration |
|
| Remove all references to external build configurations |
|
| View external build configurations referenced by the project | proj.BuildConfigurationRefs |
| Display name and path of external build configuration |
|
| Set the active build configuration for the project | proj.ActiveBuildConfiguration = buildConfigRef |
The polyspace.project.BuildConfigurationRef object has two properties:
Name— Name of the external build configurationPath— Path to the external configuration file (.pscfg) that the project references
Use the get() method of the polyspace.project.BuildConfigurationRef object to get the polyspace.project.BuildConfiguration object it references and inspect or modify that build configuration. The properties of the polyspace.project.BuildConfiguration object correspond to the
build-related options in Polyspace
Test. See Test Execution in Polyspace Platform User Interface.
This table summarizes the ways you can interact with a polyspace.project.BuildConfiguration object referenced by a polyspace.project.BuildConfigurationRef object.
| Action | Command |
|---|---|
Load existing polyspace.project.BuildConfigurationRef object and get the build configuration it references |
|
| Modify a property of the referenced external configuration | externalBuildConfig.Libraries.append("gtest.lib") |
| Save the external build configuration |
|
Save (export) a copy of the external build configuration as a .pscfg file |
|
| Unload the external build configuration from memory | externalBuildConfig.close() |
Build configuration currently active in the project, specified as a polyspace.project.OwnedBuildConfiguration or polyspace.project.BuildConfigurationRef object. The options in the active configuration are used
when you build the project using polyspace.test.build or build and run tests using polyspace.test.run.
Static analysis configurations owned by the project, returned as a polyspace.project.StaticAnalysisConfigurationList object. A polyspace.project.StaticAnalysisConfigurationList object is a list of polyspace.project.OwnedStaticAnalysisConfiguration objects. The object properties correspond to the options
related to static analysis in Polyspace
Bug Finder™ and Polyspace
Code Prover™. See Polyspace Bug Finder options (Polyspace Bug Finder) and Polyspace Code Prover options (Polyspace Code Prover).
This table summarizes the ways you can use a static analysis configuration that is owned by a project proj.
| Action | Command |
|---|---|
| Create new owned static analysis configuration | ownedStaticConfig = proj.StaticAnalysisConfigurations.create("myStaticConfig") |
| Load existing configuration | ownedStaticConfig = proj.StaticAnalysisConfigurations["Owned config name"] |
| Create owned static analysis configuration by copying an existing static analysis configuration |
Here,
Optionally, use the |
| Convert a referenced external static analysis configuration to an owned static analysis configuration |
Here, |
Export a copy of an owned static analysis configuration to a .pscfg file | ownedStaticConfig.export("filename.pscfg") |
| View available static analysis configurations owned by the project | proj.StaticAnalysisConfigurations |
| Modify a property of an owned static analysis configuration | ownedStaticConfig.Multitasking.EnableMultitasking = True |
| Display owned static analysis configuration | Quiet — Verbose — |
| Set the active static analysis configuration for the project | proj.ActiveStaticAnalysisConfiguration = ownedStaticConfig |
Since R2026a
External static analysis configurations referenced by the project, returned as a polyspace.project.StaticAnalysisConfigurationRefList object. A polyspace.project.StaticAnalysisConfigurationRefList object is a list of polyspace.project.StaticAnalysisConfigurationRef objects.
This table summarizes the ways you can interact with static analysis configurations referenced by the project proj:
| Action | Command |
|---|---|
| Add a reference to an existing external static analysis configuration |
You can provide a full or relative path to the external configuration file. Relative paths are considered relative to the location of the project. |
| Convert an owned static analysis configuration to an external configuration, referenced by the project |
Here, |
| Remove a reference to an external static analysis configuration |
|
| Remove all references to external static analysis configurations |
|
| View external static analysis configurations referenced by the project | proj.StaticAnalysisConfigurationRefs |
| Display name and path of external static analysis configuration |
|
| Set the active static analysis configuration for the project | proj.ActiveStaticAnalysisConfiguration = staticConfigRef |
The polyspace.project.StaticAnalysisConfigurationRef object has two properties:
Name— Name of the external static analysis configurationPath— Path to the external configuration file (.pscfg) that the project references
Use the get() method of the polyspace.project.StaticAnalysisConfigurationRef object to get the polyspace.project.StaticAnalysisConfiguration object it references and inspect or modify that static analysis configuration. The properties of the
polyspace.project.StaticAnalysisConfiguration object correspond to the options related to static analysis in Polyspace
Bug Finder and Polyspace
Code Prover. See Polyspace Bug Finder options (Polyspace Bug Finder) and Polyspace Code Prover options (Polyspace Code Prover).
This table summarizes the ways you can interact with a polyspace.project.StaticAnalysisConfiguration object referenced by a polyspace.project.StaticAnalysisConfigurationRef object.
| Action | Command |
|---|---|
Load existing polyspace.project.StaticAnalysisConfigurationRef object and get the static analysis configuration it references |
|
| Modify a property of the referenced external configuration | externalStaticConfig.Multitasking.EnableMultitasking = True |
| Save the external static analysis configuration |
|
Save (export) a copy of the external static analysis configuration as a .pscfg file |
|
| Unload the external static analysis configuration from memory | externalStaticConfig.close() |
Static analysis configuration currently active in the project, specified as a polyspace.project.OwnedStaticAnalysisConfiguration or polyspace.project.StaticAnalysisConfigurationRef object. The options in this
configuration are used when you run static analysis on the project using Polyspace
Bug Finder or Polyspace
Code Prover.
Testing and profiling configurations owned by the project, returned as a polyspace.project.TestConfigurationList object. A polyspace.project.TestConfigurationList object is a list of polyspace.project.OwnedTestConfiguration objects. The object properties correspond to the options related to code profiling in
Polyspace
Test. See Code Profiling in Polyspace Platform User Interface.
This table summarizes the ways you can use a test configuration that is owned by a project proj.
| Action | Command |
|---|---|
| Create new owned test configuration | ownedTestConfig = proj.TestConfigurations.create("myTestConfig") |
| Load existing configuration | ownedTestConfig = proj.TestConfigurations["Owned config name"] |
| Create owned test configuration by copying an existing test configuration |
Here,
|
| Convert a referenced external test configuration to an owned test configuration |
Here, |
Export a copy of an owned test configuration to a .pscfg file | ownedTestConfig.export("filename.pscfg") |
| View available test configurations owned by the project | proj.TestConfigurations |
| Modify a property of an owned test configuration | ownedTestConfig.CoverageOptions.Level = polyspace.project.CoverageMetricLevel.MCDC |
| Display owned test configuration | Quiet — Verbose — |
| Set the active test configuration for the project | proj.ActiveTestConfiguration = ownedTestConfig |
Since R2026a
External testing and profiling configurations referenced by the project, returned as a polyspace.project.TestConfigurationRefList object. A polyspace.project.TestConfigurationRefList object is a list of polyspace.project.TestConfigurationRef objects.
This table summarizes the ways you can interact with testing and profiling configurations referenced by the project proj:
| Action | Command |
|---|---|
| Add a reference to an existing external testing and profiling configuration |
You can provide a full or relative path to the external configuration file. Relative paths are considered relative to the location of the project. |
| Convert an owned testing and profiling configuration to an external configuration, referenced by the project |
Here, |
| Remove a reference to an external testing and profiling configuration |
|
| Remove all references to external testing and profiling configurations |
|
| View external testing and profiling configurations referenced by the project | proj.TestConfigurationRefs |
| Display name and path of external testing and profiling configuration |
|
| Set the active testing and profiling configuration for the project | proj.ActiveTestConfiguration = testConfigRef |
The polyspace.project.TestConfigurationRef object has two properties:
Name— Name of the external build configurationPath— Path to the external configuration file (.pscfg) that the project references
Use the get() method of the polyspace.project.TestConfigurationRef object to get the polyspace.project.TestConfiguration object it references and inspect or modify that testing and profiling configuration. The properties of the polyspace.project.TestConfiguration object
correspond to the options related to code profiling in Polyspace
Test. See Code Profiling in Polyspace Platform User Interface.
This table summarizes the ways you can interact with a polyspace.project.TestConfiguration object referenced by a polyspace.project.TestConfigurationRef object.
| Action | Command |
|---|---|
Load existing polyspace.project.TestConfigurationRef object and get the testing and profiling configuration it references |
|
| Modify a property of the referenced external configuration | externalTestConfig.CoverageOptions.Level = polyspace.project.CoverageMetricLevel.MCDC |
| Save the external testing and profiling configuration |
|
Save (export) a copy of the external testing and profiling configuration as a .pscfg file |
|
| Unload the external build configuration from memory | externalTestConfig.close() |
Testing and profiling configuration currently active in the project, specified as a polyspace.project.OwnedTestConfiguration or polyspace.project.TestConfigurationRef object. The options in this configuration are
used when you build the project using polyspace.test.build or build and run tests using polyspace.test.run with ProfilingSelection set to one of these:
polyspace.test.ProfilingSelection.COVERAGE(coverage computation)polyspace.test.ProfilingSelection.EXECUTION(execution profiling)polyspace.test.ProfilingSelection.STACK(stack profiling)polyspace.test.ProfilingSelection.SANITIZER(code sanitizer profiling)
Source Files and Include Folders
Source files added to the project, specified as a polyspace.project.Code object. Use the following methods to manage the list:
To add source files, use the
Files.add()method.sources = proj.Code sources.Files.add("path/to/file.c")To add source folders, use the
Folders.add()method. Set theRecursiveargument toTrueto add all subfolders recursively.sources = proj.Code sources.Folders.add("path/to/folder",Recursive=True)To remove source files, use the
Files.pop()method with a string or index value. If you do not provide an argument to theFiles.pop()method, the last file added to the list is removed.To remove all source files use thesources = proj.Code sources.Files.pop("path/to/file.c") sources.Files.pop(0)Files.clear()method.sources = proj.Code sources.Files.clear()To remove source folders, use the
Folders.pop()method with a string or index value. If you do not provide an argument to theFolders.pop()method, the last folder added to the list is removed.To remove all source folders use thesources = proj.Code sources.Folders.pop("path/to/folder") sources.Folders.pop(0)Folders.clear()method.sources = proj.Code sources.Folders.clear()
Include folders specified in the project specified as a list of polyspace.project.IncludeFolderSpec objects. Each object in the list has the following properties:
| Property | Description |
|---|---|
Path | Path to include folder. |
Recursive | Whether all subfolders are added recursively, specified as True or False. |
FollowSymLinks | Whether symbolic links must be resolved, specified as True or False. |
Use the following methods to manage the list:
To add include folders, use the
add()method. Set theRecursiveargument toTrueto add all subfolders recursively.includes = proj.IncludePaths includes.add("path/to/folder",Recursive=True)To remove include folders, use the
pop()method with an index value. If you do not provide an argument to thepop()method, the last include folder added to the list is removed.includes = proj.IncludePaths includes.pop(0)To empty the list of include folders, use the
clear()method.includes = proj.IncludePaths includes.clear()
List of project variables specified as a polyspace.project.VariablesMap object. Project variables are variables that can be used as shorthands in paths added to a project. For more information, see Project variables.
This table summarizes the ways you can modify the project variables.
| Action | Command |
|---|---|
| Get the value of a project variable |
|
| Set the value of an existing project variable, or add a new project variable. |
Note that |
| Delete a project variable. |
Before removing a project variable, make sure that it is not used anywhere in the paths added to the project. |
Stubs and Mocks
Since R2026a
Function stubs added to the project, returned as a polyspace.project.FunctionStubList object. A polyspace.project.FunctionStubList object is a list of polyspace.project.FunctionStub objects. Use the following methods to manage the list:
To create a new function stub for the
polyspace.project.FunctionobjectfunctionToStub, use thecreate()method.fcnStubs = proj.FunctionStubs newFcnStub = fcnStubs.create(functionToStub)To create a copy of an existing function stub from another project, use the
createFrom()method.fcnStubs = proj.FunctionStubs fcnStubCopy = fcnStubs.createFrom(existingFunctionStubObj)To remove an existing function stub using its name
fcnStubNameor its indexfcnStubIdx, use thepop()method. If you do not provide an argument to thepop()method, the last item in the list is removed.fcnStubs = proj.FunctionStubs fcnStubs.pop("fcnStubName") fcnStubs.pop(1)To remove all function stubs from the project, use the
clear()method.fcnStubs = proj.FunctionStubs fcnStubs.clear()
To stub undefined functions using an external C/C++ source file, see polyspace.project.Stubs.
Since R2026a
Variable stubs added to the project, returned as a polyspace.project.VariableStubList object. A polyspace.project.VariableStubList object is a list of polyspace.project.VariableStub objects. Use the following methods to manage the list:
To create a new variable stub for the
polyspace.project.GlobalobjectvariableToStub, use thecreate()method.varStubs = proj.VariableStubs newVarStub = varStubs.create(variableToStub)To create a copy of an existing variable stub from another project, use the
createFrom()method.varStubs = proj.VariableStubs varStubCopy = varStubs.createFrom(existingVariableStubObj)To remove an existing variable stub using its name
varStubNameor indexvarStubIdx, use thepop()method. If you do not provide an argument to thepop()method, the last item in the list is removed.varStubs = proj.VariableStubs varStubs.pop("varStubName") varStubs.pop(2)To remove all variable stubs from the project, use the
clear()method.varStubs = proj.VariableStubs varStubs.clear()
To stub undefined variables using an external C/C++ source file, see polyspace.project.Stubs.
Since R2026a
External C/C++ files containing stub implementations for undefined functions and variables, specified as a polyspace.project.Stubs object. Stubbing undefined functions and variables in an external C/C++ file is an alternative to using project-specific stubs for functions (polyspace.project.FunctionStub objects) and variables (polyspace.project.VariableStub objects). Using external stub files allows you to reuse existing stubs, share stubs across similar projects and write more complex stub implementations.
Since R2026a
Mocks added to the project returned as a polyspace.project.MockList object. A polyspace.project.MockList object is a custom list of polyspace.project.Mock objects. Use the following methods to manage the list:
To create a new mock using a
polyspace.project.FunctionobjectfunctionToMock, use thecreate()method.For more information, seemocks = proj.Mocks newMock = mocks.create(functionToMock)polyspace.project.Mock.To duplicate an existing
polyspace.project.MockobjectexistingMockwith a new namenewMockName, use thecreateFrom()method.For more information, seemocks = proj.Mocks newMock = mocks.createFrom(existingMock, newMockName)polyspace.project.Mock.To remove a existing mock using its name
mockName, use thepop()method.mocks = proj.Mocks mocks.pop(mockName)To remove all mocks, use the
clear()method.mocks = proj.Mocks mocks.clear()
Tests
Test suites that you author in the Polyspace Platform user interface or using the Polyspace
Test
Python API, specified as a polyspace.project.TestSuiteList object. Each individual test suite is an instance of the polyspace.project.TestSuite class. Each test suite can contain graphical test cases owned by the project or graphical test cases that are referenced by the project.
This table summarizes the ways you can modify a test suite list object proj.TestSuites, where proj is a project object.
| Action | Command |
|---|---|
| Add a new test suite |
|
| Add copy of an existing test suite |
Here, |
| Delete a test suite |
|
| Delete all test suites |
|
A polyspace.project.TestSuite object has these properties:
Name— Name of the test suite, specified as a string. You specify this name when you create the test suite.TestCases— Owned graphical test cases that the test suite contains, returned as apolyspace.project.TestCaseListobject. Each individual test case contained in this list is an instance of thepolyspace.project.OwnedTestCaseclass.This table summarizes the ways you can modify a test case list object
suite.TestCases, wheresuiteis apolyspace.project.TestSuiteobject.Action Command Add a new owned test case testCase = suite.TestCases.create("myTestCase")adds a graphical test case whoseNameproperty is set to"myTestCase".Add copy of an existing test case to the project testCase = suite.TestCases.createFrom(existingTestCase, newName)Here,
existingTestCaseis the existingpolyspace.project.OwnedTestCaseobject or the.pstestdfile to copy, andnewNameis the name to associate with the copied test case.Convert referenced test case to an owned test case testCase = testSuite.TestCases.moveAsOwned(existingTestCaseRefObj)converts the test case referenced byexistingTestCaseRefObjintestSuiteto apolyspace.project.OwnedTestCaseobject in the same test suite.Delete an owned test case suite.TestCases.pop("myTestCase")deletes the test case named"myTestCase"from the project. Alternatively, remove a test case at indexiin the list withsuite.TestCases.pop(i).Delete all owned test cases suite.TestCases.clear()removes all test cases from the list.TestCaseRefs— Test references that the test suite contains, returned as apolyspace.project.TestCaseRefListobject. A test reference is a graphical test case that you save in a.pstestdfile that is linked to the project by reference. Apolyspace.project.TestCaseRefListobject is a list ofpolyspace.project.TestCaseRefobjects. (since R2026a)This table summarizes the ways you can modify a test case ref list object
suite.TestCaseRefs, wheresuiteis apolyspace.project.TestSuiteobject.Action Command Add a reference to a .pstestdgraphical test case filetestCaseRef = suite.TestCaseRefs.add(testCaseFile, testRefName)adds a reference to the existing.pstestdgraphical test case filetestCaseFileand sets theNameproperty totestRefName.Convert owned test case to a test reference testCaseRef = suite.TestCaseRefs.moveAsRef(existingTestCase, fileName, testCaseRefName)Here,
existingTestCaseis an existingpolyspace.project.OwnedTestCaseobject,fileNameis the name to give the.pstestdfile that will be referenced by the project, andtestCaseRefNameis an optional argument to set theNameproperty of the new test case reference.Remove a test reference suite.TestCaseRefs.pop("myTestCaseRef")removes the test case reference with name"myTestCaseRef"from the project. Alternatively, remove a test case reference at indexiin the list withsuite.TestCaseRefs.pop(i).Remove all test references suite.TestCaseRefs.clear()removes all test references from the project.
Polyspace
Test xUnit test files added to the project, specified as a polyspace.project.Tests object. Use the following methods to manage the list:
To add test files, use the
Files.add()method.tests = proj.Tests tests.Files.add("path/to/file.c")To add test folders, use the
Folders.add()method. Set theRecursiveargument toTrueto add all subfolders recursively.tests = proj.Tests tests.Folders.add("path/to/folder",Recursive=True)To remove test files, use the
Files.pop()method with a string or index value. If you do not provide an argument to theFiles.pop()method, the last folder added to the list is removed.To remove all test files use thetests = proj.Tests tests.Files.pop("path/to/file.c") tests.Files.pop(0)Files.clear()method.tests = proj.Tests tests.Files.clear()To remove test folders, use the
Folders.pop()method with a string or index value. If you do not provide an argument to theFolders.pop()method, the last folder added to the list is removed.To remove all test folders use thetests = proj.Tests tests.Folders.pop("path/to/folder") tests.Folders.pop(0)Folders.clear()method.tests = proj.Tests tests.Folders.clear()
External test files added to the project, specified as a polyspace.project.ExternalTests object. Use the following methods to manage the list:
To add test files, use the
Files.add()method.tests = proj.ExternalTests tests.Files.add("path/to/file.c")To add test folders, use the
Folders.add()method. Set theRecursiveargument toTrueto add all subfolders.tests = proj.ExternalTests tests.Folders.add("path/to/folder",Recursive=True)To remove test files, use the
Files.pop()method with a string or index value. If you do not provide an argument to theFiles.pop()method, the last folder added to the list is removed.To remove all test files use thetests = proj.ExternalTests tests.Files.pop("path/to/file.c") tests.Files.pop(0)Files.clear()method.tests = proj.ExternalTests tests.Files.clear()To remove test folders, use the
Folders.pop()method with a string or index value. If you do not provide an argument to theFolders.pop()method, the last folder added to the list is removed.To remove all test folders use thetests = proj.ExternalTests tests.Folders.pop("path/to/folder") tests.Folders.pop(0)Folders.clear()method.tests=proj.ExternalTests tests.Folders.clear()
Methods
Save current project, save copy of project to new location, refresh project sources, and close project.
Here, proj = polyspace.project.Project("myProjectName")
save | Save changes in current project file. Example:
|
saveCopy | Save a copy of the project to a new location. Example:
|
refreshSources | Refresh the content of folders added to the project, if you add or remove source code, external stub files, or test files from that folder, or if you add or remove a folder from the project. Example:
|
close | Close project and unload it from memory. All project objects, methods, and properties become stale after you unload the project. Example:
|
Examples
This example shows how to create or load a Polyspace Platform project and manage the project configuration.
In general, you generate and manage Polyspace
Test projects and results by using classes from the polyspace.project and polyspace.test modules. Before starting, make sure you can import these modules on a Python shell or in a Python script without errors. For more information, see Set Up Python API for Polyspace.
Import the required modules:
import polyspace.project
import polyspace.test
Create new project and add source code and test files:
# Create new project
myProj = polyspace.project.Project("newProject")
# Add source and test files
myProj.Code.Files.add("file.c")
myProj.Tests.Files.add("test.c")Save your changes to the file system.
myProj.save()Since R2026a
When authoring a test for a C/C++ function, you can work around undefined functions and variables by replacing them with stubs. A stub for an undefined function has the same signature as the function, but a different function body, often an empty one. You can stub undefined callees in a Polyspace Platform project by writing your own external C/C++ stub files, or by creating project-specific stubs with polyspace.project.Project.FunctionStubs and polyspace.project.Project.VariableStubs. This example shows how to create default project-specific stubs for all undefined callees in a project using the Polyspace Python API.
Create the project, add your source files, and parse the code.
## Import modules
import polyspace.project
import os
## Create project
examples_path = os.path.join(polyspace.__install_path__, "polyspace",
"examples", "doc_pstest", "getting_started_test_manager")
proj = polyspace.project.Project("myProject.psprjx")
## Add source files and include path
proj.Code.Files.add(os.path.join(examples_path, "algo.c"))
proj.Code.Files.add(os.path.join(examples_path, "saturate.c"))
proj.IncludePaths.add(os.path.join(examples_path))
## Parse code
codeInfo = polyspace.project.parseCode(proj)The codeInfo object has a Functions property that contains all the functions in the source code, returned as a custom list of polyspace.project.Function objects. The codeInfo object also has a Globals property that contains all the global variables in the source code, returned as a custom list of polyspace.project.Global objects.
Use the StubbingSupport property of the polyspace.project.Function and polyspace.project.Global objects to identify which functions and variables are undefined and require stubbing. Write for-loops to identify and create default stubs for all undefined functions and variables in the project.
for f in codeInfo.Functions:
if f.StubbingSupport:
proj.FunctionStubs.create(f)
for v in codeInfo.Globals:
if v.StubbingSupport:
proj.VariableStubs.create(v)
Set the Value property of the minValue and maxValue variable stubs to -2 and 2, respectively.
minValueStub = proj.VariableStubs[0]
minValueStub.Value = "-2"
maxValueStub = proj.VariableStubs[1]
maxValueStub.Value = "2"
This example shows how to import tests that you develop in an external framework, for example GoogleTest, into a Polyspace project and then use the Python API to build and run the tests.
In general, you generate and manage Polyspace
Test projects and results by using classes from the polyspace.project and polyspace.test modules. Before starting, make sure you can import these modules on a Python shell or in a Python script without errors. For more information, see Set Up Python API for Polyspace.
Import the required modules:
import polyspace.project
import polyspace.test
import os
Create a project and define some project variables to refer to the Polyspace installation folder, the folder containing example files, and the GoogleTest installation folder.
externProj = polyspace.project.Project("externalProject")
externProj.Variables["EXAMPLESFOLDER"] = os.path.join(polyspace.__install_path__, "polyspace",
"examples", "doc_pstest")
externProj.Variables["GTESTINSTALLFOLDER"] = "/usr/local/googletest"Create a build configuration project and configure the build options for your project. For an example of how to configure your project when you import tests from GoogleTest, see Run GoogleTest Tests Using Polyspace Platform Projects.
buildConf = externProj.BuildConfigurations.create("externTestConfig")
buildConf.ExtraLinkFlags = "-pthread"
buildConf.ExternalTestsBuildOptions.IncludePaths.add("$(GTESTINSTALLFOLDER)/googletest/googletest/include")
buildConf.ExternalTestsBuildOptions.LibraryPaths.append("$(GTESTINSTALLFOLDER)/googletest/build/lib")
buildConf.ExternalTestsBuildOptions.Libraries.append("libgtest.a")
buildConf.ExternalTestsBuildOptions.Libraries.append("libgtest_main.a")Add the source and external test files to your project.
externProj.Code.Files.add("$(EXAMPLESFOLDER)/google_test/hUserCode.cpp")
externProj.ExternalTests.Files.add("$(EXAMPLESFOLDER)/google_test/hGoogleTest.cpp")Assign the build configuration object you created to the active build configuration of the project.
externProj.ActiveBuildConfiguration = buildConf
When you run the tests using res = polyspace.test.run(externProj) and print the results, you see the following output:
{
Suites Requested: 2
Suites Passed: 1
Suites Failed: 1
Suites Incomplete: 0
Tests Requested: 3
Tests Passed: 2
Tests Failed: 1
Tests Incomplete: 0
Profiling: --
}Version History
Introduced in R2024aStarting in R2026a, you can create modular Polyspace Platform projects to improve sharing and version control workflows. One way to modularize your project is by using external configurations instead of owned configurations, which are attached to a specific project. An external configuration is a build, static analysis, or testing and profiling configuration that you save in a separate .pscfg file and link to one or more projects by reference. To manage external configurations in the Polyspace
Python API use the following properties:
polyspace.project.BuildConfigurationRefspolyspace.project.StaticAnalysisConfigurationRefspolyspace.project.TestConfigurationRefs
For more information about modular project structure, see Create Easily Shareable Projects for Version Control.
In R2025b and earlier releases, every graphical test case you created in a test suite of a Polyspace Platform project was saved as a part of the project, in the .psprjx project file. Starting in 2026a, you can create modular projects and share or reuse a graphical test case across related projects by saving it in a separate .pstestd file.
To create a modular project, use test references in your test suites. A test reference is a graphical test case that is saved in a .pstestd file and linked to one or more projects by reference. To manage test references in the Polyspace
Python API use the TestCaseRefs property of the polyspace.project.TestSuite object. To manage graphical test cases that are owned by and saved in the .psprjx project file, continue using the TestCases property of the polyspace.project.TestSuite object.
For more information about modular project structure, see Create Easily Shareable Projects for Version Control.
Manage stubs and mocks in the Polyspace
Python API by using these polyspace.project.Project properties:
polyspace.project.FunctionStubspolyspace.project.VariableStubspolyspace.project.Stubspolyspace.project.Mocks
You can add graphical tests that you author using the Polyspace Test Python API.
See Also
polyspace.project.OwnedBuildConfiguration | polyspace.project.OwnedStaticAnalysisConfiguration | polyspace.project.OwnedTestConfiguration | polyspace.project.BuildConfigurationRef | polyspace.project.StaticAnalysisConfigurationRef | polyspace.project.TestConfigurationRef | polyspace.project.CodeInfo | polyspace.project.Stubs | polyspace.project.FunctionStub | polyspace.project.VariableStub | polyspace.project.Mock | polyspace.project.TestCase | polyspace.project.TestCaseRef | polyspace.test.run | polyspace.test.build | polyspace.test.TestResults | polyspace.project.TestCase
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)