Skip to content
Edit this page View source of this page

Testing

Testing

Test Guidelines

  • Coverage: 100% test coverage is required (fail_under = 100 in [tool.coverage.report] in pyproject.toml).
  • Framework: Use pytest.
  • Fixtures: Leverage tests/conftest.py for common fixtures.
  • Mocking: Use pytest.Monkeypatch for environment variables and pytest.LogCaptureFixture for logs.

Running Tests

The project runs its tasks through mise: mise test is pytest with coverage, mise all runs the full quality gate.

Run All Tests

mise test
# or: uv run pytest tests/ -v

Run a Single Test File

uv run pytest tests/test_config.py -v

Run a Single Test Function

uv run pytest tests/test_config.py::test_adobe_requires_both_credentials -v

Run Tests with Coverage

uv run pytest tests/ -v --cov=pdf_remote_converter --cov-report=term-missing

Writing Tests

Example Test

import pytest
from pdf_remote_converter.providers.cloudconvert import CloudConvertProvider


def test_cloudconvert_provider_quota():
    provider = CloudConvertProvider(api_key="test_key")
    assert provider.quota_remaining == 10

Mocking Environment Variables

import os
import pytest


def test_config_loading(monkeypatch):
    monkeypatch.setenv("CLOUDCONVERT_API_KEY", "test_key")
    from pdf_remote_converter.config import Config
    config = Config()
    assert config.cloudconvert_api_key == "test_key"

Testing Logs

import logging


def test_logging(caplog):
    with caplog.at_level(logging.INFO):
        logging.getLogger().info("Test log")
        assert "Test log" in caplog.text