Skip to content

Unit Testing

Mohamed E. Masoud edited this page Feb 10, 2025 · 5 revisions

MeshFL includes a suite of unit tests to ensure the code remains stable. We use pytest as the main testing framework.

MeshFL/
  ├─ app/
  │   └─ code/
  │       └─ executor/
  │       |    ├─ meshnet_executor.py
  │       |    ├─ meshnet.py
  │       |    ├─ loader.py
  │       |    ├─ dist.py
  │       |    ├─ dice.py
  │       |    └─ paths.py
  |       |
  │       └─ aggregator/
  │       |    └─ gradient_aggregator.py
  |       |
  │       └─ workflow/
  │           └─ gradient_aggregation_workflow.py
  |
  ├─ tests/
  │   ├─ test_meshnet_executor.py
  │   ├─ test_meshnet.py
  │   ├─ test_loader.py
  │   ├─ test_dist.py
  │   ├─ test_dice.py
  │   └─ test_paths.py
  │   └─ test_gradient_aggregation_workflow.py
  │   └─ test_gradient_aggregator.py
  |   
  ├─ requirements.txt
  └─ ...

Installation:

pip install pytest

Running Tests:

  1. Navigate to the project’s root directory:
cd /path/to/MeshFL
  1. Run pytest:

pytest

This command automatically run all test files (e.g., test_*.py) in the tests folder.

  1. Check if all tests pass, for example:
============================= test session starts ==============================
platform linux -- Python 3.8.8, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir:/MeshFL
plugins: anyio-2.2.0
collected 5 items                                                              

tests/test_dice.py .....                                                 [100%]

============================== 5 passed in 2.74s ===============================

Optional - Test Coverage

To see coverage reports, install the coverage package:

pip install coverage

Then run:

coverage run -m pytest
coverage report -m

That will show report like this example:

Name                            Stmts   Miss  Cover   Missing
-------------------------------------------------------------
app/code/executor/__init__.py       0      0   100%
app/code/executor/dice.py          15      0   100%
tests/test_dice.py                 33      0   100%
-------------------------------------------------------------
TOTAL                              48      0   100%

Clone this wiki locally