Discounted-Udemy-Course-Enroller
Discounted-Udemy-Course-Enroller copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR sets up a comprehensive testing infrastructure for the Udemy Downloader CLI project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Migrated to Poetry: Created
pyproject.tomlwith Poetry configuration - Migrated dependencies: All dependencies from
requirements.txtare now managed by Poetry - Lock file support: Poetry will generate
poetry.lockfor reproducible builds
Testing Framework
- pytest: Main testing framework with extensive configuration
- pytest-cov: Coverage reporting with 80% threshold requirement
- pytest-mock: Mocking utilities for unit tests
Configuration
Added comprehensive pytest configuration in pyproject.toml:
- Test discovery patterns for
test_*.pyand*_test.pyfiles - Coverage settings with HTML and XML report generation
- Custom test markers:
@pytest.mark.unit,@pytest.mark.integration,@pytest.mark.slow - Strict mode enabled for better test quality
Test Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_validation.py # Infrastructure validation
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Test Fixtures
Created comprehensive fixtures in conftest.py:
temp_dir: Temporary directory managementmock_settings: Mock configuration datamock_course_data/mock_lecture_data: Mock Udemy datamock_response/mock_failed_response: HTTP response mockingmock_cloudscraper: CloudScraper session mockingmock_browser_cookies: Browser cookie mockingcapture_logs: Log output capturemock_gui_window: FreeSimpleGUI window mocking- And more...
Updated .gitignore
Added entries for:
- Testing artifacts (
.pytest_cache/,coverage.xml,htmlcov/) - Poetry artifacts (keeping
poetry.locktracked) - Claude settings (
.claude/*) - Virtual environments and Python artifacts
Running Tests
Install dependencies:
poetry install
Run tests:
# Using Poetry scripts (both commands work)
poetry run test
poetry run tests
# Or directly with pytest
poetry run pytest
# Run with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
# Run with coverage report
poetry run pytest --cov
View coverage report:
# HTML report will be in htmlcov/index.html
open htmlcov/index.html
Notes
- The testing infrastructure is now ready for developers to write unit and integration tests
- Coverage threshold is set to 80% - tests will fail if coverage drops below this
- The validation test (
test_validation.py) verifies that all testing components are properly configured - GUI tests may fail in headless environments due to display requirements
- No actual unit tests for the codebase were written - only infrastructure setup
Next Steps
- Write unit tests for individual modules (
base.py,cli.py, etc.) - Write integration tests for end-to-end workflows
- Set up CI/CD pipeline to run tests automatically
- Consider adding additional testing tools (e.g.,
pytest-asynciofor async code,pytest-xdistfor parallel execution)