menu
Contribute

Creating Tests

GS Quant uses pytest to run unit tests across all packages. We track coverage across the project using pytest-cov to manage the health of the project. Some general guidelines for testing in GS Quant:

  • Organization tests live in the /test folder, where they follow the package structure of GS Quant. Please add a new folder to the tests folder if you are adding a new package to GS Quant
  • Unit Tests unit tests for Python modules should be runnable by any developer, without needing an API key. Mock API responses to ensure other developers can run all relevant tests
  • Mocking our tests use [pytest-mock] in order to simulate valid responses
  • Coverage: certain packages have 100% test coverage enforced, for example the Timeseries Package. If submitting a pull request, please follow coverage guidelines

Writing Tests

To create a new test, add your file to the relevant folder in /tests. A simple test function will look something like this:

import pytest
from pandas.util.testing import assert_series_equal
from gs_quant.timeseries import *


def test_returns():
    dates = [
        date(2019, 1, 1),
        date(2019, 1, 2),
        date(2019, 1, 3),
        date(2019, 1, 4),
        date(2019, 1, 5),
        date(2019, 1, 6),
    ]

    x = pd.Series([])
    assert_series_equal(x, returns(x))

    x = pd.Series([100.0, 101, 103.02, 100.9596, 100.9596, 102.978792], index=dates)

Running Tests

Tests are located in gs_quant/test. To run tests you will need to configure pytest and then run as follows:

gs_quant>pytest gs_quant/test

To run tests on a specific folder, simply specify the folder name as follows:

gs_quant>pytest gs_quant/test/timeseries/

You can also run tests on a specific file:

gs_quant>pytest gs_quant/test/timeseries/test_algebra.py

Output will look something like this:

======================================= test session starts =======================================
platform win32 -- Python 3.7.0, pytest-5.3.2, py-1.8.1, pluggy-0.13.1
rootdir: H:\gs_quant_2\gs_quant
plugins: cov-2.8.1, mock-1.13.0
collected 13 items

H:\gs_quant_2\gs_quant .............                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        [100%]

======================================= 13 passed in 2.77s =========================================

Test Coverage

We use pytest-cov to evaluate test coverage. In order to view test coverage, please use the --cov option:

gs_quant>pytest --cov=gs_quant --cov-report gs_quant/test/timeseries/test_algebra.py

If you want to know which statements are missing tests, use the following option:

gs_quant>pytest --cov=gs_quant --cov-report term-missing gs_quant/test

Happy testing!


Related Content


GS DAP® is owned and operated by Goldman Sachs. This site is for informational purposes only and does not constitute an offer to provide, or the solicitation of an offer to provide access to or use of GS DAP®. Any subsequent commitment by Goldman Sachs to provide access to and / or use of GS DAP® would be subject to various conditions, including, amongst others, (i) satisfactory determination and legal review of the structure of any potential product or activity, (ii) receipt of all internal and external approvals (including potentially regulatory approvals); (iii) execution of any relevant documentation in a form satisfactory to Goldman Sachs; and (iv) completion of any relevant system / technology / platform build or adaptation required or desired to support the structure of any potential product or activity. All GS DAP® features may not be available in certain jurisdictions. Not all features of GS DAP® will apply to all use cases. Use of terms (e.g., "account") on GS DAP® are for convenience only and does not imply any regulatory or legal status by such term.
Certain solutions and Institutional Services described herein are provided via our Marquee platform. The Marquee platform is for institutional and professional clients only. This site is for informational purposes only and does not constitute an offer to provide the Marquee platform services described, nor an offer to sell, or the solicitation of an offer to buy, any security. Some of the services and products described herein may not be available in certain jurisdictions or to certain types of clients. Please contact your Goldman Sachs sales representative with any questions. Any data or market information presented on the site is solely for illustrative purposes. There is no representation that any transaction can or could have been effected on such terms or at such prices. Please see https://www.goldmansachs.com/disclaimer/sec-div-disclaimers-for-electronic-comms.html for additional information.
Transaction Banking services are offered by Goldman Sachs Bank USA (“GS Bank”). GS Bank is a New York State chartered bank, a member of the Federal Reserve System and a Member FDIC.
Mosaic is a service mark of Goldman Sachs & Co. LLC. This service is made available in the United States by Goldman Sachs & Co. LLC and outside of the United States by Goldman Sachs International, or its local affiliates in accordance with applicable law and regulations. Goldman Sachs International and Goldman Sachs & Co. LLC are the distributors of the Goldman Sachs Funds. Depending upon the jurisdiction in which you are located, transactions in non-Goldman Sachs money market funds are affected by either Goldman Sachs & Co. LLC, a member of FINRA, SIPC and NYSE, or Goldman Sachs International. For additional information contact your Goldman Sachs representative. Goldman Sachs & Co. LLC, Goldman Sachs International, Goldman Sachs Liquidity Solutions, Goldman Sachs Asset Management, L.P., and the Goldman Sachs funds available through Goldman Sachs Liquidity Solutions and other affiliated entities, are under the common control of the Goldman Sachs Group, Inc.
© 2025 Goldman Sachs. All rights reserved.