Skip to content
Course Notes: Unit Testing for Data Science in Python
Course Notes
Use this workspace to take notes, store code snippets, and build your own interactive cheatsheet!
Note that the data from the course is not yet added to this workspace. You will need to navigate to the course overview page, download any data you wish to use, and add it to the file browser.
Unit testing for Data Science
# Import any packages you want to use here
import pytest
# Fill in with a context manager that will silence the ValueError
with pytest.raises(ValueError):
raise ValueError
Take Notes
Add notes here about the concepts you've learned and code cells with code you want to keep.
Add your notes here
import pytest
try:
# Fill in with a context manager that raises Failed if no OSError is raised
with pytest.raises(OSError):
raise ValueError
except:
print("pytest raised an exception because no OSError was raised in the context.")
import numpy as np
import pytest
from train import split_into_training_and_testing_sets
def test_on_one_row():
test_argument = np.array([[1382.0, 390167.0]])
# Store information about raised ValueError in exc_info
with pytest.raises(ValueError) as exc_info:
split_into_training_and_testing_sets(test_argument)
expected_error_msg = "Argument data_array must have at least 2 rows, it actually has just 1"
# Check if the raised ValueError contains the correct message
assert exc_info.match(expected_error_msg)