feat: Set up complete Python testing infrastructure with Poetry#2
Open
llbbl wants to merge 1 commit intoyongxinz:masterfrom
Open
feat: Set up complete Python testing infrastructure with Poetry#2llbbl wants to merge 1 commit intoyongxinz:masterfrom
llbbl wants to merge 1 commit intoyongxinz:masterfrom
Conversation
- Initialize Poetry as package manager with pyproject.toml - Add pytest, pytest-cov, and pytest-mock as dev dependencies - Configure comprehensive pytest and coverage settings - Create test directory structure with shared fixtures - Set up custom markers for unit, integration, and slow tests - Add validation tests to verify infrastructure setup - Update .gitignore with testing and Poetry-related entries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Set Up Python Testing Infrastructure
Summary
This PR establishes a complete testing infrastructure for the Python interview questions project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
pyproject.tomlconfigurationpytest(^8.3.3) - Core testing frameworkpytest-cov(^5.0.0) - Coverage reportingpytest-mock(^3.14.0) - Mocking utilitiesTesting Configuration
pytest Configuration:
test_*.pyfilesunit,integration,slowCoverage Configuration:
src,编程题,数据结构与算法Project Structure
Development Commands
poetry run test- Run all testspoetry run tests- Alternative command (both work)poetry run pytest [options]- Direct pytest access with all optionsShared Fixtures (in conftest.py)
temp_dir- Temporary directory for file operationstemp_file- Temporary file with contentmock_env_vars- Environment variable managementsample_data- Common test data structuressample_tree_node- Binary tree node for algorithm testssample_linked_list_node- Linked list node for algorithm testscapture_stdout- Stdout capture for testing print statementsmock_input- Mock user input for interactive codeTesting the Infrastructure
Install Dependencies
Run Tests
View Coverage Reports
htmlcov/index.htmlcoverage.xmlNotes
Poetry Lock File: The
poetry.lockfile is NOT gitignored and should be committed to ensure reproducible builds.Coverage Threshold: Set to 80% - tests will fail if coverage drops below this threshold.
Python Version: Configured for Python 3.8+ compatibility.
Test Organization: Tests are organized into
unit/andintegration/directories with automatic marker assignment based on location.Project Packages: The
srcdirectory is configured as a package, and all Python files in the project are included in coverage analysis.Next Steps
Developers can now immediately start writing tests for the existing codebase:
test_*.pynaming conventionconftest.py@pytest.mark.unit,@pytest.mark.integration, or@pytest.mark.slow