This directory contains the complete test suite for the GitLab Issues Analyzer project.
tests/
├── conftest.py # Shared fixtures and configuration
├── unit/ # Unit tests (isolated, fast)
│ ├── test_config.py
│ ├── test_gitlab_client.py
│ ├── test_analyzer.py
│ ├── test_reporter.py
│ ├── test_email_sender.py
│ └── test_monitor.py
├── integration/ # Integration tests (component interactions)
│ ├── test_gitlab_integration.py
│ ├── test_analyzer_integration.py
│ └── test_email_integration.py
└── e2e/ # End-to-end tests (full workflows)
└── test_full_workflow.py
pip install -r requirements-test.txtpytest# Unit tests only
pytest tests/unit/
# Integration tests only
pytest tests/integration/
# End-to-end tests only
pytest tests/e2e/pytest tests/unit/test_config.pypytest tests/unit/test_config.py::TestConfigLoading::test_load_config_from_environment_variablespytest --cov=src --cov-report=html --cov-report=term-missingpytest -m "not slow"pytest -m "not requires_credentials"Tests are marked with categories:
@pytest.mark.slow- Tests that take longer to run@pytest.mark.requires_credentials- Tests that need real API credentials@pytest.mark.unit- Unit tests@pytest.mark.integration- Integration tests@pytest.mark.e2e- End-to-end tests
The test suite aims for 80%+ code coverage. Current test cases cover:
- ✅ Config module (7 test cases)
- ✅ GitLab Client module (11 test cases)
- ✅ Analyzer module (10 test cases)
- ✅ Reporter module (6 test cases)
- ✅ Email Sender module (7 test cases)
- ✅ Monitor module (9 test cases)
- ✅ GitLab API integration (3 test cases)
- ✅ Analyzer integration (2 test cases)
- ✅ Email integration (1 test case)
- ✅ Complete webhook workflow (1 test case)
- ✅ Complete polling workflow (1 test case)
- ✅ Error handling workflow (1 test case)
When adding new tests:
- Follow the naming convention:
test_<function_name>_<scenario>_<expected_result>() - Use fixtures from
conftest.pywhen possible - Mock external dependencies (APIs, file system, network)
- Add appropriate markers (
@pytest.mark.slow, etc.) - Include docstrings describing what is being tested
- Reference test case IDs from
TEST_CASES.mdin docstrings
Common fixtures available in conftest.py:
sample_issue_data- Sample GitLab issue datasample_comprehensive_issue_data- Issue data with comments, related issues, attachmentssample_analysis- Sample WWWH-TR analysissample_webhook_payload- Sample GitLab webhook payloadsample_config- Sample configuration dictionarysample_smtp_config- Sample SMTP configurationmock_gitlab_response- Mock GitLab API responsemock_ai_response- Mock AI API responsemock_smtp_server- Mock SMTP server
Tests should be run in CI/CD pipelines:
- Run all unit tests on every commit
- Run integration tests on pull requests
- Run E2E tests on main branch only
- Generate coverage reports
- Fail build if coverage drops below threshold
- Unit tests use mocks for all external dependencies
- Integration tests use mocked HTTP responses
- E2E tests may require test credentials (marked with
@pytest.mark.requires_credentials) - Some tests are marked as
@pytest.mark.slowand can be skipped during development
For more details, see TEST_CASES.md.