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/

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/

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

This site is for informational purposes only and does not constitute an offer to sell, or the solicitation of an offer to buy, any security. The Goldman Sachs Marquee® platform is for institutional and professional clients only. Some of the services and products described on this site may not be available in certain jurisdictions or to certain types of client. Please contact your Goldman Sachs sales representative with any questions. Nothing on this site constitutes an offer, or an invitation to make an offer from Goldman Sachs to purchase or sell a product. This site is given for purely indicative purposes and does not create any contractual relationship between you and Goldman Sachs. Any market information contained on the site (including but not limited to pricing levels) is based on data available to Goldman Sachs at a given moment and may change from time to time. There is no representation that any transaction can or could have been effected on such terms or at such prices. Please see for additional information. © 2023 Goldman Sachs. All rights reserved.
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. © 2023 Goldman Sachs. All rights reserved.
Not all products and functionality mentioned on this website are currently available through our API platform.
All loans and deposit products are provided by Goldman Sachs Bank USA, Salt Lake City Branch. Member FDIC.
Brokerage and investment advisory services offered by our investment products are provided by Goldman Sachs & Co. LLC (`‘GS&CO.`’), which is an SEC registered broker-dealer and investment adviser, and member FINRA/SIPC. Research our firm at FINRA's BrokerCheck. Custody and clearing services are provided by Apex Clearing Corporation, a registered broker-dealer and member FINRA/SIPC. Please consider your objectives before investing. A diversified portfolio does not ensure a profit or protect against a loss. Past performance does not guarantee future results. Investment outcomes and projections are forward-looking statements and hypothetical in nature. Neither this website nor any of its contents shall constitute an offer, solicitation, or advice to buy or sell securities in any jurisdictions where GS&Co. is not registered. Any information provided prior to opening an investment account is on the basis that it will not constitute investment advice and that GS&Co. is not a fiduciary to any person by reason of providing such information. For more information about our investment offerings, visit our Full Disclosures.