selenium-python icon indicating copy to clipboard operation
selenium-python copied to clipboard

feat: Add complete Python testing infrastructure with Poetry

Open llbbl opened this issue 5 months ago • 0 comments

Add Python Testing Infrastructure

Summary

This PR sets up a complete Python testing infrastructure for the Selenium Python documentation project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry configuration
    • Set package-mode = false since this is a documentation-only project
    • Migrated dependencies from requirements.txt and setup.py
    • Added testing dependencies as dev dependencies

Testing Framework

  • pytest: Main testing framework with comprehensive configuration
  • pytest-cov: Coverage reporting with HTML and XML output
  • pytest-mock: Mocking utilities for testing

Testing Configuration

  • pytest settings in pyproject.toml:

    • Strict markers and configuration
    • Custom markers: unit, integration, slow
    • Test discovery patterns configured
    • Coverage reporting with multiple formats
  • Coverage settings:

    • Source directory configuration
    • Exclusion patterns for test files and virtual environments
    • Detailed reporting options

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared pytest fixtures
├── test_setup_validation.py  # Infrastructure validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Fixtures Added (in conftest.py)

  • temp_dir: Temporary directory for test files
  • mock_config: Mock configuration dictionary
  • sample_rst_content: Sample reStructuredText for testing
  • sphinx_build_dir: Mock Sphinx build directory structure
  • source_dir: Mock source directory with basic Sphinx structure
  • mock_sphinx_app: Mock Sphinx application object
  • reset_environment: Environment variable cleanup
  • sample_makefile_content: Sample Makefile content

Other Updates

  • Updated .gitignore with:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
    • Development files (virtual environments, IDE files)
    • Claude settings (.claude/*)

How to Use

Install Dependencies

poetry install

Run Tests

# Run all tests
poetry run pytest

# Run with verbose output
poetry run pytest -v

# Run specific markers
poetry run pytest -m unit
poetry run pytest -m integration

# Run without coverage
poetry run pytest --no-cov

View Coverage Reports

  • HTML report: Open htmlcov/index.html in a browser
  • XML report: Available at coverage.xml for CI/CD integration

Validation

The setup includes validation tests that verify:

  • All testing dependencies are properly installed
  • Project structure is correctly set up
  • Configuration files are valid and complete
  • Pytest markers work correctly
  • Fixtures are available and functional
  • Poetry commands work as expected

All validation tests pass successfully:

============================== 12 passed in 0.47s ==============================

Notes

  • This is a documentation project, so coverage requirements are relaxed
  • The Poetry scripts for test and tests commands use pytest:main entry point
  • The infrastructure is ready for developers to start writing actual tests for any Python code or utilities in the project

llbbl avatar Jun 27 '25 19:06 llbbl