Monitoring Pytest using GitHub Actions
You can integrate your GitHub Actions pipeline workflow with Foresight to monitor the Pytest runs of your Python project.

Prerequisites

The required parameters are the Thundra API Key and the Thundra Project ID, which can be obtained from the project settings screen.
Once you get your keys, make sure to set it as a secret.

Running the Command With Thundra

It is possible to run test commands by giving them to the Thundra stage like below. Please make sure that Pytest and pip have been installed. Running the Command With Thundra
1
# ...
2
3
jobs:
4
build-and-test:
5
runs-on: ubuntu-latest
6
strategy:
7
matrix:
8
python-version: [3.9]
9
10
steps:
11
- uses: actions/[email protected]
12
13
# Specify your python install step
14
- name: Set up Python
15
uses: actions/setup-[email protected]
16
with:
17
python-version: ${{ matrix.python-version }}
18
19
- name: Install Test Dependencies
20
run: |
21
pip install pytest
22
pip install -r requirements.txt
23
24
- name: Install Thundra Python Agent
25
uses: thundra-io/thundra-foresight-python-[email protected]
26
with:
27
apikey: ${{ secrets.THUNDRA_APIKEY }}
28
project_id: ${{ secrets.THUNDRA_PROJECT_ID }}
29
command: pytest
Copied!

Running the Command Separately

If you have already steps that run your tests by using Pytest, installing "Thundra Python Github Action" is all you need with using THUNDRA_APIKEYand THUNDRA_PROJECT_ID as secrets.
1
# ...
2
3
jobs:
4
build-and-test:
5
runs-on: ubuntu-latest
6
strategy:
7
matrix:
8
python-version: [3.9]
9
10
steps:
11
- uses: actions/[email protected]
12
13
# Specify your python install step
14
- name: Set up Python
15
uses: actions/setup-[email protected]
16
with:
17
python-version: ${{ matrix.python-version }}
18
19
- name: Install Test Dependencies
20
run: |
21
pip install pytest
22
pip install -r requirements.txt
23
24
- name: Install Thundra Python Agent
25
uses: thundra-io/thundra-foresight-python-[email protected]
26
with:
27
apikey: ${{ secrets.THUNDRA_APIKEY }}
28
project_id: ${{ secrets.THUNDRA_PROJECT_ID }}
29
30
- name: Run Tests
31
run: pytest
Copied!

Known Issues

Using It with Build Matrix

If you are using a build matrix in your workflow, each run in your build matrix will show up like it's a different testrun on Thundra Foresight where in fact they belong to the same build.
With the current GitHub Action context, it's not possible to understand that those runs belogs to the same run. So, the obvious solution is to set a unique testrun ID for these runs before the matrix starts.
To solve this problem and other issues if we need to, we've written the Thundra Test Init Action.
Make sure to follow the instruction in the repository.

Parameters

Name
Requirement
Default
Description
apikey
Required
---
Thundra API Key
project_id
Required
---
Your project id from Thundra. Will be used to filter and classify your testruns.
test_disable
Optional
False
Disable Thundra
framework
Optional
pytest
Test framework type. Currently only pytest framework is allowed.
command
Optional
---
The pytest command you want to run.
agent_version
Optional
---
A specific version Thundra Python Agent you want to use should be defined here. If this value is not specified latest version of Thundra Python Agent will be use.
Last modified 1mo ago