Testing Guide¶
Guide for writing and running tests in Weeb CLI.
Test Structure¶
Tests are located in tests/ directory:
tests/
├── __init__.py
├── conftest.py # Pytest fixtures
├── test_providers.py # Provider tests
├── test_cache.py # Cache tests
├── test_database.py # Database tests
└── ...
Running Tests¶
All Tests¶
Specific Test File¶
Specific Test¶
With Coverage¶
View coverage: open htmlcov/index.html
Writing Tests¶
Basic Test¶
Using Fixtures¶
def test_with_fixture(temp_dir):
# temp_dir provided by conftest.py
file_path = temp_dir / "test.txt"
assert file_path.parent.exists()
Mocking¶
from unittest.mock import Mock, patch
def test_with_mock():
with patch('module.function') as mock_func:
mock_func.return_value = "mocked"
result = call_function()
assert result == "mocked"
Test Categories¶
Unit Tests¶
Test individual functions:
Integration Tests¶
Test component interaction:
def test_provider_search():
provider = get_provider("animecix")
results = provider.search("test")
assert len(results) > 0
End-to-End Tests¶
Test complete workflows (use sparingly).
Best Practices¶
- One assertion per test when possible
- Use descriptive test names
- Mock external dependencies
- Clean up resources
- Test edge cases
Next Steps¶
- Contributing: Contribution guide
- Architecture: System design