Create and Test Custom Task Scripts



Before you can create and test custom task scripts for your self-service Tetra Data pipelines (SSPs), you must do the following:

  • Initialize the TetraScience Software Development Kit (SDK) 2.0 environment.
  • Configure Tetra Data Platform (TDP) dependencies and authentication.

For more information, see SSP Setup and Prerequisites.

To create and test custom task scripts for self-service Tetra Data pipelines (SSPs), do the following.

Create a Custom Task Script

To create a custom task script, see Create and Deploy a Task Script in the β€œHello, World!” SSP Example.



For more information about task script files and their formatting, see Task Script Files.

Modify Your Custom Task Script Folder Structure for Testing Purposes

To test a custom task script’s functionality locally, you must modify it in the following ways.

Testing Task Script Folder Structure

Modify your local task script folder so that it has the following structure:

β”œβ”€β”€ __tests__
β”‚Β Β  β”œβ”€β”€
β”‚Β Β  └──
β”œβ”€β”€ sspdemo_taskscript
β”‚Β Β  β”œβ”€β”€
β”‚Β Β  └──
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ config.json

For this example setup, the folder is restructured in the following way:

  • The folder name of the task script has dashes. The contents of the folder are the TetraScience specific content (for example,, requirements.txt, config.json, and
  • A new subfolder named sspdemo_taskscript is created that is a Python package that can be imported for testing. This new subfolder contains the business-relevant functions. It has the same folder name as the task-script, but has underscores instead of dashes (to allow for importing). To be a Python package, it must contain an file, but it can be empty.
  • A new subfolder named _tests_ is created that is a Python package that is used for testing when calling pytest. The Python files in this folder import the relevant functions in the sspdemo_taskscript Python module. To be a Python package, it must contain an file, but it can be empty.
  • The file now has the functions that are exposed by the **config.json** file. However, it calls the functions from the sspdemo_taskscript package, which have been tested.

Add ts-sdk to the Python Package

To test a task script locally and import the Context API in, you must add it to the Python package by running the following Python Poetry command on the command line in the top-level task script folder:

poetry add ts-sdk



If you're going to re-upload this task script to the TDP, make sure that you modify the requirements.txt file by exporting the Python Poetry dependencies. For instructions, see Create a Python Package in the β€œHello, World!” SSP Example.

Create a Python Package With Task Script Functions and Modified File

Modify the sspdemo-taskscript/sspdemo_taskscript subfolders so that they include the functions that you want to use in your task script and test. Then, modify the file to import the sspdemo_taskscript package and use the relevant functions it contains.


from ts_sdk.task.__task_script_runner import Context

# The actual function we are using and testing
def print_hello_world(input: dict, context):
    print("Hello World!")
    return "Hello World!"


from ts_sdk.task.__task_script_runner import Context
from sspdemo_taskscript.print_hello_world import print_hello_world

# Now our calls the functions from the python package we created
# If there were inputs to pass along, it would also do that. Here we pass
# empty arguments
print_hello_world(input={}, context={}) 

Create a Test Python File (

In this example setup, the print_hello_world function in the file calls the print_hello_world function in the sspdemo_taskscript Python package. The print_hello_world function takes in two arguments (input and context) and returns a string with the following value: "Hello World!"

To create a test case that demonstrates that the function is working as intended, create a file in a text editor with the following text, and then save it in your _tests_ folder.


from sspdemo_taskscript.main import print_hello_world

def test_hello_world():
    output = print_hello_world(input={}, context={})
    assert output == "Hello World!"

Test the Setup

In your local command line, navigate to the sspdemo-taskscript directory. Then, run the following Python Poetry command:

$ poetry run pytest

If you receive a Command not found: pytest error, try removing and then adding the pytest package again by running the following commands:

poetry remove pytest
poetry add pytest



When you run pytest, it will run through all of the tests in your test directory and then provide a summary of which tests passed and failed.