Set up Python testing infrastructure with Poetry and pytest#61
Open
llbbl wants to merge 1 commit into
Open
Conversation
- Migrate from requirements.txt to Poetry package management - Add pytest, pytest-cov, and pytest-mock as dev dependencies - Configure comprehensive test settings in pyproject.toml - Create organized test directory structure with fixtures - Set up coverage reporting with 80% threshold - Update .gitignore with testing artifacts - Add Poetry script commands for running tests
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 comprehensive testing infrastructure for the Django online education platform using Poetry for dependency management and pytest as the testing framework.
Changes Made
Package Management
pyproject.tomlwith all dependencies fromrequirements.txtTesting Configuration
pyproject.tomlwith:Directory Structure
Test Fixtures (conftest.py)
Created comprehensive fixtures for common testing needs:
temp_dir: Temporary directory managementmock_config: Mock configuration objectsclient/authenticated_client: Django test clientstest_user/test_superuser: User fixturesmock_request: HTTP request mockingsample_file/sample_image: File upload testingmock_cache: Cache testingcaptured_emails: Email testingmock_datetime: Time mockingAdditional Setup
poetry run testandpoetry run testscommandsHow to Use
Install dependencies:
Run all tests:
Run specific test categories:
Generate coverage report:
poetry run pytest --cov-report=html # Open htmlcov/index.html in browserImportant Notes
Python Version Compatibility
The project uses Django 1.11.28 which has compatibility issues with Python 3.10 and above due to removed
collections.Iterator. The pyproject.toml specifiespython = ">=3.6,<3.10"to ensure compatibility.Recommended Python versions: 3.6, 3.7, 3.8, or 3.9
Next Steps
Testing the Setup
The PR includes validation tests to verify the infrastructure:
test_setup_validation.py: Comprehensive infrastructure checkstest_basic_setup.py: Basic pytest functionality testsThese tests verify that: