Skip to content

feat: Add complete Python testing infrastructure with Poetry #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 27, 2025

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

- Set up Poetry as package manager with package-mode disabled for docs project
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure comprehensive pytest settings with markers and coverage reporting
- Create proper test directory structure with unit/integration subdirectories
- Add shared pytest fixtures for Sphinx documentation testing
- Update .gitignore with testing and development entries
- Add 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