Testing
This document provides information about testing the OneWorldSync Python Client.
Test Structure
The test suite is organized as follows:
tests/conftest.py: Contains pytest fixtures used across multiple test filestests/test_auth.py: Tests for the authentication moduletests/test_client.py: Tests for the API clienttests/test_models.py: Tests for the data modelstests/test_exceptions.py: Tests for the custom exceptionstests/test_utils.py: Tests for the utility functionstests/test_integration.py: Integration tests that make actual API calls
Running Tests
To run the tests, use pytest:
# Run all tests
pytest
# Run tests with verbose output
pytest -v
# Run a specific test file
pytest tests/test_client.py
# Run a specific test
pytest tests/test_client.py::test_client_init_with_params
Integration Tests
Integration tests are disabled by default because they require valid API credentials and will make actual API calls. To enable them, set the ONEWORLDSYNC_RUN_INTEGRATION_TESTS environment variable to true:
# Enable integration tests
export ONEWORLDSYNC_RUN_INTEGRATION_TESTS=true
pytest tests/test_integration.py
Test Coverage
To run tests with coverage reporting:
# Install pytest-cov if not already installed
pip install pytest-cov
# Run tests with coverage
pytest --cov=oneworldsync
# Generate HTML coverage report
pytest --cov=oneworldsync --cov-report=html
Mocking
Most tests use mocking to avoid making actual API calls. The unittest.mock module is used to mock:
API responses
Authentication
Environment variables
Adding New Tests
When adding new tests:
Follow the existing pattern of test files
Use fixtures from
conftest.pywhere appropriateMock external dependencies
Test both success and error cases
Add docstrings to explain what each test is checking