Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 26, 2025

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.toml with Poetry configuration
  • Migrated dependencies: All dependencies from requirements.txt are now managed by Poetry
  • Lock file support: Poetry will generate poetry.lock for 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_*.py and *_test.py files
  • 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 management
  • mock_settings: Mock configuration data
  • mock_course_data / mock_lecture_data: Mock Udemy data
  • mock_response / mock_failed_response: HTTP response mocking
  • mock_cloudscraper: CloudScraper session mocking
  • mock_browser_cookies: Browser cookie mocking
  • capture_logs: Log output capture
  • mock_gui_window: FreeSimpleGUI window mocking
  • And more...

Updated .gitignore

Added entries for:

  • Testing artifacts (.pytest_cache/, coverage.xml, htmlcov/)
  • Poetry artifacts (keeping poetry.lock tracked)
  • 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

  1. Write unit tests for individual modules (base.py, cli.py, etc.)
  2. Write integration tests for end-to-end workflows
  3. Set up CI/CD pipeline to run tests automatically
  4. Consider adding additional testing tools (e.g., pytest-asyncio for async code, pytest-xdist for parallel execution)

- Set up Poetry as package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting (80% threshold)
- Create test directory structure with unit/integration folders
- Add comprehensive test fixtures in conftest.py
- Update .gitignore with testing and Poetry-related entries
- Create validation tests to verify infrastructure setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant