Set up Python testing infrastructure with Poetry and pytest #61
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.toml
with all dependencies fromrequirements.txt
Testing Configuration
pyproject.toml
with: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 test
andpoetry run tests
commandsHow 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 browser
Important 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: