Getting Started with snowflake-vcrpy
In a recent blog post we announced a new PyTest plugin, snowflake-vcrpy, which can dramatically speed up your test suite by recording your requests to Snowflake and replaying the responses in following executions. We wanted to follow-up on that announcement with a demo showing how to get started, and an example of how we use snowflake-vcrpy internally.
Get started with snowflake-vcrpy
The demo video below shows how to install snowflake-vcrpy, configure it for a test case, and use it in a GitHub Actions workflow for CI/CD.
Clone this repository and follow along with the video below! The README has instructions for setting your Snowflake credentials to run the tests and the GitHub Actions workflow.
Using snowflake-vcrpy internally
To illustrate how snowpark-vcrpy can help speed up the test running, let’s take a look at the test suite tests/integ/scala in the official snowpark-python library. This suite is composed of 825 test cases, each sending requests to Snowflake. Let’s run this test suite without snowflake-vcrpy…
$ git clone git@github.com:snowflakedb/snowpark-python.git
$ cd snowpark-python
$ pip install ".[pandas,development]"
# set up ./tests/parameters.py prior to running the tests
$ pytest ./tests/integ/scala
The full suite took just over 20 minutes. Now let’s run the test with snowflake-vcrpy. Remember that this first-time run will write all the cassette files, but once they’re in place…
$ pytest ./tests/integ/scala --snowflake-record-tests-selection all
The second time you run it the tests are run against the local recordings, which only took 2 minutes — 10% of the original time! There are failures because some of the tests are based on randomly generated local files and data. We plan to support those scenarios in the future, but as a short term workaround those failures could be fixed by updating the tests to use static files or constant data.