Sharing Simulation Functions

If you want to share code between multiple cocotb testbenches, you can place re-usable Python modules in a test_api directory in your project. These Python modules can then be imported in any testbenches in your project, or projects that depend on your project.

Put these routines into a test_api directory.

You need to add an empty test_api/__init__.py so that Python recognizes the directory as a module.

From your test Python code you can now use them like so:

# ...
import <swim_project_name>.<some_module>
from <swim_project_name>.<some_module> import <something>
# ...

Python will place bytecode next to the Python files in the test_api directory. Add the following to your .gitignore to ignore them automatically.

# Python Bytecode
**/__pycache__