New PyTest and migrated 3 other tests#887
Conversation
…d 3 others(test_blackformula_pytest, test_bondfunctions_pytest, test_bonds_pytest) from unittest to PyTest Thank you
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
New PyTest and migrated 3 other tests
There was a problem hiding this comment.
Pull request overview
This PR introduces new pytest-based Python test modules for QuantLib-SWIG: it adds a new Asian options test suite and adds pytest equivalents for three existing unittest-based suites (Black formula, BondFunctions, Bonds).
Changes:
- Added a new pytest-style
test_asianoptions.pycovering multiple Asian option engines/cases. - Added pytest versions of existing unittest suites: bonds, bond functions, and black formula.
- Introduced pytest fixtures for common setup/teardown in the migrated tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| Python/test/test_bonds_pytest.py | Pytest migration of the Bonds unittest suite using fixtures. |
| Python/test/test_bondfunctions_pytest.py | Pytest migration of the BondFunctions unittest suite using a fixture. |
| Python/test/test_blackformula_pytest.py | Pytest migration of the BlackFormula and BlackDeltaCalculator unittest suite. |
| Python/test/test_asianoptions.py | New pytest-based Asian options coverage across multiple engines and scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ql.Settings.instance().evaluationDate = ql.Date() | ||
| 'settlement_days': settlement_days, | ||
| 'face_amount': face_amount, | ||
| 'redemption': redemption, | ||
| 'issue_date': issue_date, | ||
| 'maturity_date': maturity_date, | ||
| 'calendar': calendar, | ||
| 'settlement_date': settlement_date, | ||
| 'day_counter': day_counter, | ||
| 'sched': sched, | ||
| 'coupons': coupons, | ||
| 'bond': bond, | ||
| 'flat_forward': flat_forward, | ||
| 'term_structure_handle': term_structure_handle | ||
| } |
| import math | ||
| import pytest | ||
| import QuantLib as ql | ||
|
|
|
|
||
| engine = ql.AnalyticContinuousGeometricAveragePriceAsianEngine(process) | ||
|
|
||
| payoff = ql.PlainVanillaPayoff(ql.Option.Put, strike = 85.0) |
| dt = round(360.0 / future_fixings) | ||
| fixing_dates = [today + int(i * dt) for i in range(1, future_fixings + 1)] | ||
| exercise = ql.EuropeanExercise(today + 360) | ||
| payoff = ql.PlainVanillaPayoff(ql.Option.Call, strike = 100.0) |
| with pytest.raises(Exception): | ||
| seasoned_geom.NPV() | ||
|
|
||
| ql.Settings.instance().evaluationDate = ql.Date() |
| import QuantLib as ql | ||
| import pytest | ||
|
|
|
The conversion should edit the original tests, not add duplicates with a In any case, note that porting tests from the C++ test suite to Python add very little value. The C++ tests already check that the library works, and SWIG is pretty reliable in exporting C++ code, so there's no need to check that again (unless we're adding specific features or syntax in the SWIG wrappers). I'd suggest putting effort elsewhere. |
Hi Luigi, I created a new PyTest for test_asianoptions.py and migrated 3 others(test_blackformula_pytest, test_bondfunctions_pytest, test_bonds_pytest) from unittest to PyTest
Thank you