Testing
Unit Tests
The Interactive Experimentation Engine (IEE) project includes a comprehensive set of unit tests to ensure the correctness and reliability of the backend functionality. Unit tests focus on testing individual functions or classes in isolation, without depending on external services like MLflow or MongoDB.
Testing Framework
Unit tests are implemented using pytest, a flexible Python testing framework that allows:
-
Test discovery based on file and function naming conventions
-
Marking tests with custom tags (e.g.,
unit,integration) -
Capturing and asserting logs and warnings
-
Parametrized tests for multiple inputs
Test Structure
All unit tests are located under:
backend/tests/unit
The typical structure is:
unit/ ├── test_files_read_installed_packages.py ├── test_files_create_records.py ├── test_notebook_creation.py └── ...
Each test module focuses on a specific backend functionality:
| Test Module | Purpose |
|---|---|
|
Verifies
functions that read installed or available Python packages
( |
|
Tests file and notebook
record creation logic ( |
|
Ensures the notebook creation scripts correctly generate new notebooks, handle templates, and respect permissions |
Example Test Case
@pytest.mark.unit
def test_create_file_records_basic(tmp_path, monkeypatch):
"""
Test basic functionality of createFileRecords. Creates a temporary file and checks
if the returned record matches expected values.
"""
monkeypatch.setattr("app.models.files.CONFIG", FakeConfig)
base = tmp_path / "data-exploration"
base.mkdir()
file1 = base / "test.txt"
file1.write_text("hello")
result = createFileRecords(str(base))
assert len(result) == 1
record = result[0]
assert record["file_name"] == "test.txt"
assert record["environment_id"] == "data_exploration"
assert "notebooks/test.txt" in record["notebook_url"]
assert record["size"] == str(os.stat(file1).st_size)
Running Unit Tests
To execute the unit tests, navigate to the backend/tests directory and
run:
pytest -v -m "unit" --rootdir=backend/tests -c backend/tests/pytest.ini
This will:
-
Discover all tests marked as
unit -
Use the
pytest.iniconfiguration for warnings, output formatting, and test options -
Print a verbose output for easier debugging