-
Notifications
You must be signed in to change notification settings - Fork 0
feat: update lint and test workflows #1
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces comprehensive testing infrastructure and linting workflows to the SBP Portal Backend. The changes modernize the codebase with Python 3.10+ type hints, add extensive test coverage across all service layers, and establish CI/CD pipelines for automated quality checks.
Key Changes:
- Added comprehensive test suite with 90% coverage requirement across services, routes, schemas, and main application
- Introduced GitHub Actions workflows for linting (ruff, black, mypy) and test coverage with Codecov integration
- Modernized type hints from
Optional[X],Dict,Listto Python 3.10+ syntax (X | None,dict,list)
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/conftest.py | Adds shared test fixtures including mock clients, sample data, and environment setup for all tests |
| tests/test_main.py | Tests FastAPI app creation, health endpoint, CORS configuration, and router inclusion |
| tests/test_schemas.py | Validates Pydantic schema validation, field requirements, and data transformations |
| tests/test_services_seqera.py | Tests Seqera Platform integration including workflow launches, error handling, and API interactions |
| tests/test_services_datasets.py | Tests dataset creation, upload, CSV conversion, and form data handling |
| tests/test_routes_workflows.py | Tests workflow API endpoints including launch, cancel, list, logs, and details |
| tests/test_additional_coverage.py | Provides additional tests to meet coverage thresholds for edge cases |
| tests/init.py | Marks the tests directory as a Python package |
| pytest.ini | Configures pytest with async mode, test paths, and marker definitions |
| pyproject.toml | Defines project metadata and configuration for coverage, ruff, black, and mypy |
| requirements-dev.txt | Specifies development dependencies for testing and linting |
| .pre-commit-config.yaml | Configures pre-commit hooks for automated code quality checks |
| .github/workflows/lint.yml | CI workflow for running ruff, black, and mypy linters |
| .github/workflows/test-coverage.yml | CI workflow for running tests with coverage reporting to Codecov |
| .github/PULL_REQUEST_TEMPLATE.md | Template to standardize pull request descriptions |
| app/main.py | Updates type hints to modern Python 3.10+ syntax |
| app/services/seqera.py | Modernizes type hints and improves code formatting consistency |
| app/services/datasets.py | Updates type hints to Python 3.10+ syntax and improves readability |
| app/schemas/workflows.py | Converts all type hints to modern syntax (pipe union notation) |
| app/routes/workflows.py | Updates type hints and adds proper exception chaining with from exc |
| README.md | Adds CI badges, updates Python version requirement, and documents testing/linting procedures |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
marius-mather
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests and CI checks look great, just a few suggestions on project and testing setup that will hopefully make things easier down the line.
You don't have to use the testing/mocking libraries like respx or polyfactory - just wanted to point them out as I find them useful for my own testing.
| branches: [main, workflows] | ||
| pull_request: | ||
| branches: [main, workflows] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is right - you generally only need CI to run on pushes or pull requests to main
| run: | | ||
| python -m pip install --upgrade pip | ||
| python -m pip install -r requirements.txt | ||
| python -m pip install ruff black mypy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These types of requirements should be in requirements-dev.txt so you can run the same checks locally (or in pyproject.toml as discussed below)
| @@ -0,0 +1,7 @@ | |||
| # Development dependencies | |||
| pytest==8.3.3 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd encourage you to look at uv for managing dependencies, instead of just using pip and requirements.txt. You can have dev dependencies as a dependency group.
A couple of tips:
- Add any dependencies required for dev/testing with
uv add --dev pytest - Don't pin exact versions, allow minor version upgrades by using version specifiers like
pytest ~= 8.3. I find that if you pin dependencies to exact versions, it just creates a lot of work later when you need to update something, as you have to figure out which other versions need to be updated. Also, you want to regularly update packages for security updates.
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_httpx_response(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a look at the respx library for mocking httpx - it will handle a lot of this for you
|
|
||
|
|
||
| @pytest.fixture | ||
| def sample_form_data(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also have a look at polyfactory for generating mock responses automatically from schemas - can save time if you need to specify some fields in a schema for a test but don't care about the rest.
| from app.services.datasets import DatasetUploadResult | ||
|
|
||
|
|
||
| class TestUploadDataset: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally don't use test classes when using pytest - you can just use individual test functions and use fixtures for any setup that's required.
Pull Request
SBP-232 Enable BindFlow Workflow Execution from Input Workflow Page
Summary
This PR introduces comprehensive testing infrastructure and automated quality checks to the SBP Portal Backend, establishing a solid foundation for maintainability and code quality. The changes include 93% test coverage (exceeding the 90% requirement), modern Python 3.10+ type hints, and CI/CD pipelines for automated testing and linting.
Changes
Testing Infrastructure (70 tests, 93.14% coverage)
CI/CD Workflows
release-simple.yml:Project Configuration
Coverage by Module
How to Test
Running Tests Locally
Running Linters
Pre-commit Hooks
CI/CD Validation
Type of change
Checklist