Testing Mastoscore

This section covers the testing framework and practices used in the Mastoscore project.

Overview

Mastoscore uses pytest as its testing framework. The tests are organized in the tests/ directory at the root of the project. The test suite includes unit tests for individual modules and integration tests that verify the interaction between different components.

See subsections: * Writing Tests * Test Coverage

Running Tests

To run the tests, you can use any of the following commands from the project root directory:

# Run all tests
poetry run pytest

# Run specific test files
python -m pytest tests/test_config.py

# Run specific test functions
python -m pytest tests/test_config.py::test_read_config_with_valid_file

Test Structure

The test suite is organized as follows:

Fixtures

Fixtures are defined in conftest.py and provide reusable test data and objects. Key fixtures include:

Writing Tests

When writing tests for Mastoscore, follow these guidelines:

  1. Test one thing at a time: Each test function should focus on testing a single aspect of functionality.
  2. Use descriptive names: Test function names should clearly describe what they're testing.
  3. Use fixtures: Leverage the fixtures in conftest.py to avoid duplicating setup code.
  4. Mock external dependencies: Use pytest-mock to mock external services like the Mastodon API.
  5. Test edge cases: Include tests for error conditions and edge cases.

Example Test

def test_check_journaldir_existing_directory(temp_directory):
    """Test check_journaldir with an existing directory."""
    # The temp_directory fixture creates a directory that exists
    result = check_journaldir(temp_directory)
    assert result is True