Skip to main content
Version: 1.2

Mocking Secrets and Resources

With Feature Views that depend on secrets or resources, you can define unit tests that mock up the necessary input data, secrets and resources and assert that you're getting the expected result. The MockContext class can be used to mock any secrets or resources that are required by the Feature View.

You can use the TestRepo fixture to access the Feature View and run feature retrieval methods for testing.

### tests/transaction_amount_is_high.py ###
from tecton import MockContext, TestRepo
import pandas

# Testing the 'transaction_amount_is_high' feature which depends on request data ('amount') as input
def test_transaction_amount_is_high(repo_fixture: TestRepo):
transaction_amount_is_high = repo_fixture.get_feature_view("transaction_amount_is_high")
transaction_request = pandas.DataFrame({"amount": [124, 10001, 34235436234]})

# Use a MockContext to mock any secrets or resources
mock_context = MockContext(secrets={"my_secret": "my_secret_value"})
actual = transaction_amount_is_high.run_transformation(
input_data={
"transaction_request": transaction_request,
"context": mock_context,
},
).to_pandas()

expected = pandas.DataFrame({"transaction_amount_is_high": [0, 1, 1]})
pandas.testing.assert_frame_equal(actual, expected)

Was this page helpful?