Skip to content

Testing

Inkfeed uses pytest for its test suite.

Running Tests

pip install -e ".[dev]"
pytest

Run specific tests:

# Run a specific test file
pytest tests/test_config.py

# Run tests matching a pattern
pytest -k "hackernews"

# Run with verbose output
pytest -v

Test Structure

Tests live in the tests/ directory at the root of the Inkfeed app:

tests/
├── __init__.py
├── test_config.py
├── test_archiver_*.py
├── test_output_*.py
└── ...

Writing Tests

Testing Archivers

When testing archivers, mock HTTP responses to avoid hitting real APIs:

from unittest.mock import patch, MagicMock
from inkfeed.archiver.rss import RSSArchiver

def test_rss_archiver():
    source = MagicMock()
    source.url = "https://example.com/rss.xml"
    source.max_articles = 5

    archiver = RSSArchiver(source, Path("output"))

    with patch("httpx.get") as mock_get:
        mock_get.return_value.text = "<rss>...</rss>"
        result = archiver.run(max_workers=1, max_retries=1)

    assert len(result.groups) > 0

Testing Writers

Writers can be tested by providing mock ArchiveResult objects and checking the output files:

from pathlib import Path
from inkfeed.output.markdown import MarkdownWriter

def test_markdown_writer(tmp_path):
    writer = MarkdownWriter(config)
    writer.setup()

    entries = writer.write_source(mock_result, tmp_path, "2026-02-18")

    assert len(entries) > 0
    # Check output files exist
    assert (tmp_path / "md" / "2026-02-18").exists()

    writer.teardown()

Test Coverage

To run with coverage reporting:

pip install pytest-cov
pytest --cov=inkfeed --cov-report=term-missing