From 86a437cc86e89e4de0b40a1a92a4245a7454a90c Mon Sep 17 00:00:00 2001 From: mattmenefee Date: Sat, 7 Mar 2026 17:29:18 -0500 Subject: [PATCH 1/2] Restore OREAnalyticsTestSuite.test() and drop nose from tutorials The 1.8.17.0 move of ORE-SWIG's OREAnalytics suite to pytest folded its runner into the __main__ guard and removed the module-level test() function. ORE-SWIG's setup.py test command still imports the module and calls test(), so `python setup.py test` -- the workflow in the Windows build tutorial -- now fails with an AttributeError before any test runs. test() is back, wrapping the same pytest invocation, and __main__ calls it. It exits non-zero from inside test() because setup.py inspects no return value: returning the code instead would let a failing suite report success. It resolves the test directory from the absolute path of __file__, so collection no longer depends on how the module was located. The documented workflows still referenced nose. The Windows build tutorial installed pynose alongside pytest, and the Docker tutorial invoked the examples suite with nose plugin flags that pytest rejects outright; both now describe the pytest equivalents. --- ORE-SWIG/test/OREAnalyticsTestSuite.py | 9 +++++++-- ORE-SWIG/tutorials.03.build_windows.md | 2 +- tutorials/tutorials.030.docker.md | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ORE-SWIG/test/OREAnalyticsTestSuite.py b/ORE-SWIG/test/OREAnalyticsTestSuite.py index 94fab7ac53..f45ab7daf8 100644 --- a/ORE-SWIG/test/OREAnalyticsTestSuite.py +++ b/ORE-SWIG/test/OREAnalyticsTestSuite.py @@ -7,7 +7,12 @@ import pytest import ORE -if __name__ == '__main__': +def test(): print('testing ORED ' + ORE.__version__) - sys.exit(pytest.main([os.path.dirname(__file__)])) + exit_code = pytest.main([os.path.dirname(os.path.abspath(__file__))]) + if exit_code != 0: + sys.exit(exit_code) + +if __name__ == '__main__': + test() diff --git a/ORE-SWIG/tutorials.03.build_windows.md b/ORE-SWIG/tutorials.03.build_windows.md index 57d94718f1..d8351f2051 100644 --- a/ORE-SWIG/tutorials.03.build_windows.md +++ b/ORE-SWIG/tutorials.03.build_windows.md @@ -92,7 +92,7 @@ setup.py. python -m venv env1 .\env1\Scripts\activate.bat python -m pip install --upgrade pip - python -m pip install build pynose pytest setuptools + python -m pip install build pytest setuptools python setup.py wrap python setup.py build python setup.py test diff --git a/tutorials/tutorials.030.docker.md b/tutorials/tutorials.030.docker.md index ad19a5f6ed..f0f50a463d 100644 --- a/tutorials/tutorials.030.docker.md +++ b/tutorials/tutorials.030.docker.md @@ -62,7 +62,7 @@ Invoke the command below to run the docker container interactively: Here are the commands to run the examples: cd /ore/Examples - python3 run_examples_testsuite.py --with-xunitmp --xunitmp-file=examples.xml --processes=8 --process-timeout=3600 + pytest run_examples_testsuite.py --junitxml=examples.xml -n 8 --timeout=3600 Here are the commands to run all of the unit tests in parallel: From 4cc5f8502c656744e8d20b528dd8e74ccb27f383 Mon Sep 17 00:00:00 2001 From: Matt Menefee Date: Tue, 28 Jul 2026 17:28:15 -0600 Subject: [PATCH 2/2] Repair the Windows Python test script after SWIG restructure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit runPythonTests.cmd still pointed at OREAnalytics-SWIG\Python\build and OREAnalytics-SWIG\Python\Test, neither of which survived the move of the Python suite to ORE-SWIG\test, so every path in the script was wrong and neither suite ran. Its QuantLib block also invoked QuantLibTestSuite.test() through an inline `python -c`, and that module disappeared when QuantLib-SWIG adopted plain pytest. testrunner.py is the current QuantLib entry point and already does the one thing those tests require — aliasing QuantLib to ORE in sys.modules before collection, since all of them import QuantLib rather than ORE. The script now delegates to it instead of reimplementing it inline. Its default target was stale in the same way, naming the vanished QuantLibTestSuite; it now derives the QuantLib-SWIG test directory from __file__ so it no longer depends on the caller's working directory, and propagates pytest's exit code rather than only printing it. PYTHONPATH is picked up by globbing the setup.py build output, which generalizes the version-pinned path in tutorials.03.build_windows.md and stays a no-op for anyone who ran `python setup.py install`. The pause calls are gone in favor of errorlevel checks so a failing suite fails the script; this trades away readable output when the file is launched by double-click. --- ORE-SWIG/runPythonTests.cmd | 23 ++++++++++++++++------- ORE-SWIG/test/testrunner.py | 8 ++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ORE-SWIG/runPythonTests.cmd b/ORE-SWIG/runPythonTests.cmd index 44ca5c5c25..2d37b39b5b 100644 --- a/ORE-SWIG/runPythonTests.cmd +++ b/ORE-SWIG/runPythonTests.cmd @@ -1,12 +1,21 @@ -set PYTHONPATH=%PYTHONPATH%;%~dp0\OREAnalytics-SWIG\Python\build;%~dp0\OREAnalytics-SWIG\Python\build\Release +@echo off +setlocal + +REM Run the Python test suites against a locally built ORE module. +REM Picks up the setup.py build output; harmless no-op if you installed +REM the package instead with `python setup.py install`. +for /d %%d in ("%~dp0build\lib.*") do set "PYTHONPATH=%PYTHONPATH%;%%d" + +cd /d "%~dp0test" + echo RUN ORE Python Testsuite -cd %~dp0\OREAnalytics-SWIG\Python\Test python OREAnalyticsTestSuite.py -pause +if errorlevel 1 exit /b 1 +REM testrunner.py aliases QuantLib to ORE before collection, which the +REM QuantLib-SWIG tests require; they import QuantLib, not ORE echo RUN QuantLib Testsuite -cd %~dp0\QuantLib-SWIG\Python\test -python -c "import sys, ORE; sys.modules['QuantLib']=ORE;import QuantLibTestSuite;QuantLibTestSuite.test()" -pause +python testrunner.py +if errorlevel 1 exit /b 1 -cd %~dp0\ \ No newline at end of file +echo All Python test suites passed diff --git a/ORE-SWIG/test/testrunner.py b/ORE-SWIG/test/testrunner.py index 9ef1a63ba3..50e94aa0f4 100644 --- a/ORE-SWIG/test/testrunner.py +++ b/ORE-SWIG/test/testrunner.py @@ -5,7 +5,11 @@ sys.modules["QuantLib"] = ORE +QUANTLIB_TESTS = os.path.join(os.path.dirname(os.path.abspath(__file__)), + os.pardir, "QuantLib-SWIG", "Python", "test") + if __name__=="__main__": - pytest_args = sys.argv[1:] or ["../QuantLibTestSuite"] + pytest_args = sys.argv[1:] or [QUANTLIB_TESTS] ret_code = pytest.main(pytest_args) - print("PyTest Return Code: ", ret_code) \ No newline at end of file + print("PyTest Return Code: ", ret_code) + sys.exit(ret_code)