Local Testing Guide for Speckle Automate Functions
This guide explains how to set up and run local tests for your Speckle Automate functions, allowing you to validate your automation logic before deployment.
Prerequisites
Before running local tests, you'll need:
- A Speckle project where you can create test automations
- A test automation set up in your project
- A Personal Access Token (PAT) from Speckle
- Your project and automation IDs from the test automation URL
Environment Setup
1. Create Environment Variables
Create a .env file in your project root with the following variables:
SPECKLE_TOKEN=your_personal_access_token
SPECKLE_SERVER_URL=https://app.speckle.systems
SPECKLE_PROJECT_ID=your_project_id
SPECKLE_AUTOMATION_ID=your_automation_id
2. Test Configuration
The repository includes a conftest.py that loads these environment variables for testing:
import os
from dotenv import load_dotenv
def pytest_configure(config):
load_dotenv(dotenv_path=".env")
token_var = "SPECKLE_TOKEN"
server_var = "SPECKLE_SERVER_URL"
# ... validation logic ...
Running Tests
Test Structure
Each exercise has its own test file (e.g., local_test_exercise0.py). The tests:
- Initialize an automation context
- Run the function with test inputs
- Validate the results
Example test structure:
def test_function_run(test_automation_run_data, test_automation_token):
automation_context = AutomationContext.initialize(
test_automation_run_data, test_automation_token
)
automate_sdk = run_function(
automation_context,
automate_function,
FunctionInputs(comment_phrase="Test Comment")
)
assert automate_sdk.run_status == AutomationStatus.SUCCEEDED
Running Individual Tests
To run tests for a specific exercise:
# Exercise 0
pytest tests/local_test_exercise0.py::test_function_run
# Exercise 1
pytest tests/local_test_exercise1.py::test_function_run
# Exercise 2
pytest tests/local_test_exercise2.py::test_function_run
# Exercise 3
pytest tests/local_test_exercise3.py::test_function_run
Test Automation Setup
- Navigate to your project's Automations tab
- Click "New Automation"
- Select "Create Test Automation" in the bottom left
- Follow the configuration steps
Note
: You must be a project owner and have published your function to create test automations.
Understanding Test Results
Test runs provide insights into:
- Function execution success/failure
- Business logic validation
- Interaction with Speckle project data
- Result generation and attachment
Results can be viewed:
- In your terminal during test execution
- On the automation page in your Speckle project
- In the project's automation status display
Additional Resources
For more detailed information about testing Speckle Automate functions, see:
- Function Testing Documentation
- Python SDK Documentation
- Example Function Repositories
Limitations and Notes
- Test automations require you to be a project owner
- The function must be published with at least one release
- Test automations run in a sandbox environment
- Function inputs are set in your development environment, not the UI
- Future updates may add restrictions on test automation ownership
Troubleshooting
If you encounter issues:
- Verify your environment variables are correctly set
- Ensure your PAT has the necessary permissions
- Check that your test automation is properly configured
- Validate your function inputs match the expected schema
For additional help, refer to the Speckle documentation or contact support.