Monitoring Pytest Tests with Any CI Provider
Foresight is a project powered by Thundra Agent to show every detail for test runs. Although it is automatically enabled after installing Thundra as pip install thundra, you need to set THUNDRA_APIKEY and THUNDRA_AGENT_TEST_PROJECT_ID as described below.
1
pip install thundra
Copied!

Activating Thundra Foresight

First, you need to set up the environment for Thundra. There are three ways to do it.
The required parameters are the Thundra API Key and the Thundra Project ID, which can be obtained from the project settings screen.

1) Configuring by environment variables

Add THUNDRA_APIKEY and THUNDRA_AGENT_TEST_PROJECT_ID as environment variables
1
export THUNDRA_APIKEY=<your_apikey>
2
export THUNDRA_AGENT_TEST_PROJECT_ID=<your_test_project_id>
Copied!

2) Configuring by .env file

Add thundra_apikey and thundra_agent_test_project_id in you .env file.
1
thundra_apikey =<your_apikey>
2
thundra_agent_test_project_id = <your_test_project_id>
Copied!
Then, load them in conftest.py file like below:
1
# This method requires python >= 3.5
2
from pathlib import Path
3
4
from dotenv import load_dotenv
5
6
env_path = Path(<your_env_file_name>)
7
load_dotenv(dotenv_path=env_path)
Copied!

3) Importing Thundra in conftest file and configure it.

1
import thundra
2
3
thundra.configure(
4
options={
5
"config": {
6
"thundra.apikey": <your_apikey>,
7
"thundra.agent.test.project.id": <your_test_project_id>
8
}
9
}
10
)
Copied!

Deactivating Thundra Foresight

There are three ways to deactivate Thundra Foresight for pytest:
1) Run pytest with --thundra_disable command on terminal for specific pytest run.
1
pytest --thundra_disable <your_tests_path>
Copied!
2) Modifying any configuration file read by pytest (pytest.ini, setup.cfg, pyproject.toml etc.) Please read carefully pytest official documentation for configuration files.
1
[pytest]
2
# or [tool.pytest.ini_options]
3
thundra_disable = 1
Copied!
3) Setting THUNDRA_AGENT_TEST_DISABLE=True as an environment variable.

Notes

  • All Thundra Agent features are valid in Foresight. It's default enabled. If you see more information about your test cases, you can visit Thundra APM. If you want to disable Thundra Agent for tracing, you can set THUNDRA_AGENT_DISABLE as an environment variable, thundra_agent_disable in the .env file or thundra.agent.disable into thundra.configure() to True as described above.
Last modified 1mo ago