xlsx2csv icon indicating copy to clipboard operation
xlsx2csv copied to clipboard

Add comprehensive testing infrastructure with Poetry

Open llbbl opened this issue 4 months ago • 0 comments

About UnitSeeker

Hi! This PR is part of the UnitSeeker project, a human-guided initiative to help Python repositories establish testing infrastructure.

Key points:

  • Human-approved: Every PR is manually approved before work begins
  • Semi-automated with oversight: Created and controlled via a homegrown wrapper around Claude Code with human quality control
  • Infrastructure only: This PR intentionally contains only the testing setup without actual unit tests
  • Your repository, your rules: Feel free to modify, reject, or request changes - all constructive feedback is welcome
  • Follow-up support: All responses and discussions are personally written, not automated

Learn more about the project and see the stats on our progress at https://unitseeker.llbbl.com/


Summary

This PR establishes a complete testing infrastructure for the xlsx2csv project using Poetry as the package manager. The setup provides a production-ready testing environment where developers can immediately start writing and running tests.

Changes Made

Package Management

  • ✅ Added Poetry configuration to pyproject.toml
  • ✅ Set Python requirement to ^3.9 (required by latest pytest and coverage tools)
  • ✅ Maintained compatibility with existing setuptools build system

Testing Dependencies

Added as development dependencies:

  • pytest (^8.3.0) - Modern testing framework
  • pytest-cov (^6.0.0) - Coverage reporting with HTML/XML output
  • pytest-mock (^3.14.0) - Advanced mocking utilities

Testing Configuration

Configured in pyproject.toml:

pytest settings:

  • Test discovery in tests/ directory
  • Coverage threshold set to 80%
  • Multiple report formats (HTML, XML, terminal)
  • Strict mode enabled for better error detection
  • Custom markers for test categorization:
    • @pytest.mark.unit - Unit tests
    • @pytest.mark.integration - Integration tests
    • @pytest.mark.slow - Long-running tests

Coverage settings:

  • Source tracking for xlsx2csv module
  • Exclusions for test files and common patterns
  • HTML reports in htmlcov/ directory

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures
├── test_infrastructure.py  # Validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures (conftest.py)

Provides ready-to-use fixtures:

  • temp_dir - Temporary directory with auto-cleanup
  • temp_file - Temporary file creation
  • sample_csv_content - Sample CSV data
  • sample_xlsx_path - Path to test XLSX files
  • test_data_dir - Access to existing test data
  • reset_environment - Environment variable isolation
  • mock_config - Mock configuration dictionary
  • capture_output - Output capture utility

Validation Tests

Created test_infrastructure.py with 14 tests that verify:

  • ✅ pytest installation and functionality
  • ✅ Python version compatibility
  • ✅ Project structure and modules
  • ✅ Custom markers configuration
  • ✅ All shared fixtures
  • ✅ pytest-mock integration

All validation tests pass successfully.

Running Tests

Install dependencies

poetry install

Run all tests

poetry run pytest

Run with verbose output

poetry run pytest -v

Run specific test categories

# Run only unit tests
poetry run pytest -m unit

# Run only integration tests
poetry run pytest -m integration

# Exclude slow tests
poetry run pytest -m "not slow"

Run without coverage

poetry run pytest --no-cov

Generate coverage report

poetry run pytest --cov=xlsx2csv --cov-report=html
# Open htmlcov/index.html to view report

Configuration Notes

Python Version

  • Minimum Python version set to 3.9 (required by pytest-cov ^6.0)
  • The project already supports Python 3.9+ based on classifiers
  • This aligns well with the existing compatibility range

Coverage Threshold

  • Set to 80% in pytest configuration
  • Can be adjusted in [tool.pytest.ini_options] section of pyproject.toml
  • Coverage failures will not block validation tests (infrastructure only)

Compatibility with Existing Tests

  • The existing test/ directory with XLSX/CSV test files remains unchanged
  • The existing test/run script continues to work as before
  • New tests/ directory is for pytest-based unit and integration tests

Next Steps

The testing infrastructure is now ready for use. Developers can:

  1. Start writing unit tests in tests/unit/
  2. Add integration tests in tests/integration/
  3. Use the shared fixtures from conftest.py
  4. Run tests with poetry run pytest
  5. View coverage reports to identify untested code

Files Modified

  • pyproject.toml - Added Poetry and testing configuration
  • .gitignore - Added test artifacts and IDE exclusions

Files Added

  • tests/__init__.py
  • tests/conftest.py
  • tests/test_infrastructure.py
  • tests/unit/__init__.py
  • tests/integration/__init__.py
  • poetry.lock - Dependency lock file

Thank you for considering this contribution! The testing infrastructure is intentionally minimal and unopinionated, giving you full control over how to write tests for your codebase. Feel free to modify any configuration to better suit your project's needs.

llbbl avatar Oct 09 '25 20:10 llbbl