This directory contains the test suite for the PyFed library. The tests are written using pytest and are organized into different categories.
tests/
├── unit_tests/ # Unit tests for individual components
│ ├── models/ # Tests for ActivityPub models
│ ├── serializers/ # Tests for serialization/deserialization
└── pytest.ini # Pytest configuration
- Python 3.9+
- pytest
- pytest-asyncio
- pytest-cov
pip install . # Install packagesFrom the project root directory:
pytestpytest tests/unit_tests/models/ # Run model tests only
pytest tests/unit_tests/serializers/ # Run serializer tests only
pytest tests/integration_tests/ # Run integration tests onlypytest --cov=pyfed tests/The test suite uses the following configuration from pytest.ini:
asyncio_mode = auto: Enables automatic async test detectionpythonpath = ../src: Adds source directory to Python pathaddopts = --import-mode=importlib: Uses importlib for imports
- Place unit tests in the appropriate subdirectory under
unit_tests/ - Use descriptive test names that indicate what is being tested
- Follow the pattern:
test_<what>_<expected_behavior>
def test_serialize_note():
"""Test serialization of a basic Note object."""
note = APNote(
id="https://example.com/notes/123",
content="Hello, World!"
)
serialized = note.serialize()
assert serialized["type"] == "Note"
assert serialized["content"] == "Hello, World!"- Use
pytest -vfor verbose output - Use
pytest -sto see print statements - Use
pytest --pdbto drop into debugger on failures
- Create test files in the appropriate directory
- Follow existing naming conventions
- Add necessary imports and fixtures
- Document test purpose with docstrings