Created
January 18, 2020 20:54
-
-
Save Tinitto/5501923c80d763a7ad6de8e73f34c62c to your computer and use it in GitHub Desktop.
Sample code showing how to do snapshot testing in Data Science Pipelines and Systems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pickle | |
# ...... more code | |
# ...... | |
results = some_calculation() | |
expected_result_file_path = 'path_to_the_snapshot_file_of_choice' | |
# the snapshot file should not exist at the beginning | |
if not os.path.isfile(expected_result_file_path): | |
# create the snapshot on the first run or anytime it is deleted manually | |
with open(expected_result_file_path, 'wb') as expected_results_file: | |
pickle.dump(results, expected_results_file) | |
with open(expected_result_file_path, 'rb') as expected_results_file: | |
# the actual test to compare against snapshot | |
expected_results = pickle.loads(expected_results_file) | |
# here is an assertion basing on a unittest test | |
self.assertEqual(results, expected_results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment