Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Set up comprehensive Python testing infrastructure#70

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
llbbl wants to merge1 commit into4GeeksAcademy:master
base:master
Choose a base branch
Loading
fromUnitSeeker:add-testing-infrastructure

Conversation

llbbl
Copy link

Set up comprehensive Python testing infrastructure

Summary

This PR establishes a complete testing infrastructure for the Python Functions Programming Exercises project, providing developers with a ready-to-use environment for writing and running tests.

Changes Made

Package Management

  • Poetry Setup: Addedpyproject.toml with Poetry configuration as the package manager
  • Dependencies: Added essential testing dependencies as dev dependencies:
    • pytest (v7.4.0+) - Main testing framework
    • pytest-cov (v4.1.0+) - Coverage reporting
    • pytest-mock (v3.11.0+) - Mocking utilities

Testing Configuration

  • Pytest Configuration: Comprehensive pytest setup inpyproject.toml:
    • Test discovery patterns for various file naming conventions
    • Coverage settings with 80% threshold requirement
    • HTML and XML coverage report generation
    • Strict marker and config enforcement
    • Custom markers:unit,integration,slow,it (LearnPack compatibility)

Directory Structure

  • Test Organization: Created proper testing directory hierarchy:
    tests/├── __init__.py├── conftest.py          # Shared fixtures and configuration├── unit/│   └── __init__.py├── integration/│   └── __init__.py└── test_infrastructure.py  # Validation tests

Shared Testing Utilities

  • Comprehensive Fixtures intests/conftest.py:
    • temp_dir - Temporary directory management
    • mock_config - Configuration mocking
    • app - Dynamic exercise module loading
    • mock_print /mock_input - Built-in function mocking
    • capture_stdout - Output capture utilities
    • sample_data - Common test data structures
    • mock_file_system - File system mocking
    • environment_vars - Environment variable mocking

Development Workflow

  • Git Integration: Updated.gitignore with testing exclusions:
    • Coverage files (.coverage,htmlcov/,coverage.xml)
    • Test caches (.pytest_cache/)
    • Virtual environments and IDE files
    • Note:poetry.lock is tracked (not ignored) as per best practices

Validation & Quality

  • Infrastructure Tests: Added comprehensive validation tests to ensure:
    • All fixtures work correctly
    • Directory structure is proper
    • Project compatibility is maintained
    • Testing utilities function as expected

How to Run Tests

Install Dependencies

poetry install

Run All Tests

poetry run pytest# All testspoetry run python -m pytest# Alternative command

Run Specific Test Categories

poetry run pytest -m unit# Unit tests onlypoetry run pytest -m integration# Integration tests onlypoetry run pytest -m slow# Slow tests only

Run With Coverage

poetry run pytest --cov=exercises# With coverage (default)poetry run pytest --no-cov# Without coverage

Generate Coverage Reports

poetry run pytest# Generates HTML (htmlcov/) and XML reports

Testing Features

  • Coverage Reporting: 80% threshold with detailed HTML and XML reports
  • Flexible Test Discovery: Supports multiple naming conventions
  • Mocking Utilities: Built-in fixtures for common mocking scenarios
  • Exercise Compatibility: Dynamic module loading for exercise-based testing
  • Performance Testing: Support for slow test markers
  • LearnPack Integration: Compatible with existing@pytest.mark.it markers

Notes

  • No Unit Tests Written: This PR focuses solely on infrastructure setup, not writing actual tests for the codebase
  • Backward Compatibility: Existing exercise tests should continue to work (with updated fixtures)
  • Ready for Development: Developers can immediately start writing tests using the provided fixtures and configuration
  • Lock File Management:poetry.lock is tracked in version control for reproducible builds

Validation

All validation tests pass, confirming:

  • ✅ Testing infrastructure works correctly
  • ✅ Fixtures and utilities are functional
  • ✅ Coverage reporting generates properly
  • ✅ Project structure is maintained
  • ✅ Dependencies install successfully

- Add Poetry package manager with pyproject.toml configuration- Install testing dependencies: pytest, pytest-cov, pytest-mock- Create organized test directory structure (tests/, unit/, integration/)- Configure pytest with coverage reporting (80% threshold, HTML/XML output)- Add comprehensive shared fixtures in conftest.py for common testing needs- Support for custom test markers (unit, integration, slow, it)- Update .gitignore with testing-related exclusions- Include validation tests to verify infrastructure functionalityReady-to-use testing environment where developers can immediately start writing tests.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@llbbl

[8]ページ先頭

©2009-2025 Movatter.jp