.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:
- 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). - 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). - Create a Python file with a .py extension inside the pythonlib directory.
- Write your custom Python function inside this file.
- 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()