Skip to main content

.py Files

TesmonLang allows you to import and use custom Python scripts in your tests. This can be useful for adding more complex dynamic behavior or functionality. To import a Python script into a Tesmon test, you need to follow these steps:

  1. Create a directory named pythonlib at the root level of your Tesmon project (the name of this directory is case-sensitive and must be an exact match).
  2. Update your Tesmon tesmon.config.yml file to include the pythonlib directory (more details on tesmon.config.yml can be found in the Tesmon documentation).
  3. Create a Python file with a .py extension inside the pythonlib directory.
  4. Write your custom Python function inside this file.
  5. Reference the Python function in your TesmonLang test using the following syntax:
<filename>.<function>()

For example, if your Python file is named my_functions.py and contains a function named do_something, you would reference it in your Tesmon test as my_functions.do_something().

Example

This example shows how to use a custom UUID generator in your test.

uuidgen.py
import uuid
def generate():
return str(uuid.uuid4())
scripts.yml
scripts:
generateUserId: |-
import uuidgen
context["user_id"] = uuidgen.generate()