Skip to content

Commit ea112c8

Browse files
authored
Merge pull request #49 from intersystems/PreloadModules
PreloadModules
2 parents 9d140db + ffe63c7 commit ea112c8

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- #46: Fix for bug caused by UpdateComplexity calling GetCurrentByName unnecessarily and causing dependency issues
1313
- #47: Fixed mapping issue caused by empty lines at top of Python method not showing up in compiled Python
1414
- #48: When the Line-By-Line Monitor resumes after pausing, resume the Python tracer too
15+
- #49: Added user parameter for preloading python modules (fixes problem of pandas breaking sys.settrace on first import)
1516

1617
## [4.0.0] - 2024-08-01
1718

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ zw ##class(TestCoverage.Utils).GrantSQLReadPermissions("_PUBLIC")
5757
### Running Tests with Coverage
5858
Generally speaking, set `^UnitTestRoot`, and then call `##class(TestCoverage.Manager).RunTest()` the same you would call `##class(%UnitTest.Manager).RunTest()`. For more information on InterSystems' %UnitTest framework, see the [tutorial](https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=TUNT) and/or the [class reference for %UnitTest.Manager](https://docs.intersystems.com/irislatest/csp/documatic/%25CSP.Documatic.cls?PAGE=CLASS&LIBRARY=%25SYS&CLASSNAME=%25UnitTest.Manager).
5959

60-
The "userparam" argument can be used to pass information about code coverage data collection. For example:
60+
The "userparam" argument can be used to pass optional information about code coverage data collection. For example:
6161

6262
```
6363
Set tCoverageParams("CoverageClasses") = <$ListBuild list or %DynamicArray of class names for which code coverage data should be collected>
6464
Set tCoverageParams("CoverageRoutines") = <$ListBuild list or %DynamicArray of routine names for which code coverage data should be collected>
6565
Set tCoverageParams("CoverageDetail") = <0 to track code coverage overall; 1 to track it per test suite (the default); 2 to track it per test class; 3 to track it per test method.>
66+
Set tCoverageParams("ProcessIDs") = <$ListBuild list of process IDs to monitor, or "Interoperability">
67+
Set tCoverageParams("Timing") = <1 to capture timing data, 0 to not>
68+
Set tCoverageParams("PyModules") = <$ListBuild list of Python module names to preload>
69+
Set tCoverageParams("ListenerManager") = <instance of TestCoverage.Listeners.ListenerManager>)
6670
Do ##class(TestCoverage.Manager).RunTest(,,.tCoverageParams)
6771
```
6872

@@ -96,6 +100,9 @@ Where:
96100
* `tSourceNamespace` (optional) specifies the namespace in which classes were compiled, defaulting to the current namespace. This may be required to retrieve some metadata.
97101
* `tPIDList` (optional) has a $ListBuild list of process IDs to monitor. If this is empty, all processes are monitored. If this is $ListBuild("Interop") or "Interoperability", all interoperability processes and the current process are monitored. By default, only the current process is monitored.
98102
* `tTiming` (optional) is 1 to capture execution time data for monitored classes/routines as well, or 0 (the default) to not capture this data.
103+
* `tListenerManager` (optional) is an instance of TestCoverage.Listeners.ListenerManager that allows downstream applications to listen to the completion of unit test suites/cases/methods. It should use the AddListener method to populate with listeners that extend TestCoverage.Listeners.ListenerInterface. See [isc.perf.ui](https://github.com/intersystems/isc-perf-ui) for an example usage
104+
* `tPyModules` a $ListBuild list of Python module names the covered code uses that should be imported before the unit tests are run. This is for modules like `pandas` and `sklearn`, whose import sometimes breaks sys.settrace
105+
99106

100107
### Running Tests with Coverage via IPM
101108

cls/TestCoverage/Manager.cls

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Property ListenerManager As TestCoverage.Listeners.ListenerManager;
9595
/// </ul>
9696
/// Granular data is stored in <class>TestCoverage.Data.Coverage</class>; aggregated data is stored per class in <class>TestCoverage.Data.Aggregate.ByCodeUnit</class> and for the whole run in <class>TestCoverage.Data.Aggregate.ByRun</class>.
9797
/// @API.Method
98-
ClassMethod RunAllTests(pPackage As %String = "", pLogFile As %String = "", pCoverageClasses As %List = "", pCoverageRoutines As %List = "", pCoverageLevel As %Integer = 1, ByRef pLogIndex As %Integer, pSourceNamespace As %String = {$Namespace}, pPIDList = {$ListBuild($Job)}, pTiming As %Boolean = 0) As %Status
98+
ClassMethod RunAllTests(pPackage As %String = "", pLogFile As %String = "", pCoverageClasses As %List = "", pCoverageRoutines As %List = "", pCoverageLevel As %Integer = 1, ByRef pLogIndex As %Integer, pSourceNamespace As %String = {$Namespace}, pPIDList = {$ListBuild($Job)}, pTiming As %Boolean = 0, pListenerManager As TestCoverage.Listeners.ListenerManager = "", pPyModules As %List = "") As %Status
9999
{
100100
#dim tUnitTestManager As TestCoverage.Manager
101101
Set tSuccess = 1
@@ -117,6 +117,8 @@ ClassMethod RunAllTests(pPackage As %String = "", pLogFile As %String = "", pCov
117117
Set tCoverageParams("SourceNamespace") = pSourceNamespace
118118
Set tCoverageParams("ProcessIDs") = pPIDList
119119
Set tCoverageParams("Timing") = pTiming
120+
Set tCoverageParams("ListenerManager") = pListenerManager
121+
Set tCoverageParams("PyModules") = pPyModules
120122
Do ..RunTest(tTestSuite,tSpec,.tCoverageParams)
121123

122124
Set tFailed = 0
@@ -629,6 +631,7 @@ ClassMethod OnBeforeAllTests(manager As TestCoverage.Manager, dir As %String, By
629631
Set tSourceNamespace = $Get(userparam("SourceNamespace"),$Namespace)
630632
Set tListenerManager = $Get(userparam("ListenerManager"))
631633
Set tProcessIDs = $Get(userparam("ProcessIDs"),$ListBuild($Job))
634+
Set tPyModules = $Get(userparam("PyModules"))
632635
If (tProcessIDs = "*") {
633636
Set tProcessIDs = ""
634637
} ElseIf ((tProcessIDs = "Interoperability") || (tProcessIDs = "interoperability")) {
@@ -687,6 +690,11 @@ ClassMethod OnBeforeAllTests(manager As TestCoverage.Manager, dir As %String, By
687690
set tObj = {"message": "Starting tests"}
688691
Do manager.ListenerManager.BroadCastToAll(tObj)
689692
}
693+
set tPointer = 0
694+
while $ListNext(tPyModules, tPointer, tCurModule) {
695+
do ##class(%SYS.Python).Import(tCurModule)
696+
}
697+
690698
If (manager.CoverageDetail = 0) {
691699
Set tSC = manager.StartCoverageTracking()
692700
$$$ThrowOnError(tSC)

0 commit comments

Comments
 (0)