Skip to content

New PyTest and migrated 3 other tests#887

Open
chiragpdesai77 wants to merge 9 commits into
lballabio:masterfrom
chiragpdesai77:master
Open

New PyTest and migrated 3 other tests#887
chiragpdesai77 wants to merge 9 commits into
lballabio:masterfrom
chiragpdesai77:master

Conversation

@chiragpdesai77

Copy link
Copy Markdown
Contributor

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

chiragpdesai77 and others added 8 commits July 10, 2026 13:06
…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
Copilot AI review requested due to automatic review settings July 17, 2026 07:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py covering 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.

Comment on lines +84 to +98
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
}
Comment on lines +24 to +27
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()
Comment on lines +20 to +22
import QuantLib as ql
import pytest

@lballabio

Copy link
Copy Markdown
Owner

The conversion should edit the original tests, not add duplicates with a _pytest suffix.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants