- All unit tests are located in the
tests/
directory. - Test files should be named with the pattern
test_*.py
. - Each test function should start with
def test_...
. - Example:
def test_my_function(): assert my_function(2) == 4
- Install dependencies (preferably in a virtual environment):
pip install -r requirements.txt pip install . pip install pytest coverage
- Run all tests:
pytest
- Run tests with coverage:
coverage run -m pytest coverage report
- To generate a coverage XML file (required for SonarQube/SonarCloud):
coverage run -m pytest coverage xml
- This will create a
coverage.xml
file in the project root.
-
On every push or pull request, GitHub Actions will:
- Install dependencies.
- Run tests with coverage:
coverage run -m pytest coverage xml
- Cache the
.coverage
andcoverage.xml
files. - On the main branch, the workflow restores the coverage files and runs the SonarQube scan.
-
The SonarQube/SonarCloud GitHub Action automatically picks up the
coverage.xml
file and uses it to report code coverage in the Sonar dashboard.
You do not need to manually upload coverage files—this is handled by the workflow.
Original repo here - https://github.com/Mastercard/client-encryption-python License is MIT License, as of 18th August 2025