Skip to content

feat: Set up comprehensive Python testing infrastructure #220

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

Closed
wants to merge 3 commits into from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 24, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the OpenFaaS Workshop Python functions. It introduces Poetry as the package manager and configures pytest as the testing framework with coverage reporting.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry setup
  • Dependency Migration: Migrated all dependencies from individual requirements.txt files
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • pytest Settings: Configured in pyproject.toml with:

    • Strict markers and configuration
    • Coverage reporting (HTML, XML, terminal)
    • 80% coverage threshold
    • Custom markers: unit, integration, slow
  • Coverage Settings: Configured coverage to:

    • Track all function handlers
    • Exclude test files and virtual environments
    • Generate multiple report formats

Directory Structure

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

Fixtures Added

  • temp_dir: Temporary directory management
  • mock_env: Environment variable mocking
  • mock_requests: Requests library mocking
  • mock_github_client: PyGithub client mocking
  • sample_handler_event: OpenFaaS event fixture
  • sample_github_payload: GitHub webhook payload fixture
  • mock_config_file: Configuration file fixture
  • capture_logs: Log capturing fixture

Additional Updates

  • Updated .gitignore with testing artifacts and common exclusions
  • Added validation tests to ensure infrastructure works correctly

How to Use

Install Dependencies

poetry install

Run Tests

Both commands work:

poetry run pytest

Run Tests with Options

poetry run pytest -v                    # Verbose output
poetry run pytest -k "test_name"        # Run specific test
poetry run pytest -m unit               # Run only unit tests
poetry run pytest --no-cov              # Skip coverage

View Coverage Reports

  • Terminal: Automatically shown after test runs
  • HTML: Open htmlcov/index.html in browser
  • XML: Available at coverage.xml for CI integration

Notes

  • The 80% coverage threshold is configured but will fail initially since no actual function tests exist yet
  • All OpenFaaS function directories are included in coverage tracking
  • The infrastructure is ready for immediate test development
  • Poetry lock file is committed for reproducible builds

- Add Poetry as package manager with pyproject.toml configuration
- Configure pytest with coverage reporting and custom markers
- Create testing directory structure with unit/integration separation
- Add shared pytest fixtures for common testing patterns
- Update .gitignore with testing and build artifacts
- Add validation tests to verify infrastructure setup
Copy link

derek bot commented Jun 24, 2025

Thank you for your contribution. unfortunately, one or more of your commits are missing the required "Signed-off-by:" statement. Signing off is part of the Developer Certificate of Origin (DCO) which is used by this project.

Read the DCO and project contributing guide carefully, and amend your commits using the git CLI. Note that this does not require any cryptography, keys or special steps to be taken.

💡 Shall we fix this?

This will only take a few moments.

First, clone your fork and checkout this branch using the git CLI.

Next, set up your real name and email address:

git config --global user.name "Your Full Name"
git config --global user.email "you@domain.com"

Finally, run one of these commands to add the "Signed-off-by" line to your commits.

If you only have one commit so far then run: git commit --amend --signoff and then git push --force.
If you have multiple commits, watch this video.

Check that the message has been added properly by running "git log".

@derek derek bot added the no-dco label Jun 24, 2025
- Add Poetry as package manager with pyproject.toml configuration
- Configure pytest with coverage reporting and custom markers
- Create testing directory structure with unit/integration separation
- Add shared pytest fixtures for common testing patterns
- Update .gitignore with testing and build artifacts
- Add validation tests to verify infrastructure setup

Signed-off-by: Logan Lindquist <logan@llbbl.com>
Signed-off-by: llbbl <logan@llbbl.com>
@llbbl
Copy link
Author

llbbl commented Jun 30, 2025

ok, I think I did it;

git commit --amend -s --no-edit

and edited the commit message as well

@rgee0
Copy link
Contributor

rgee0 commented Jul 1, 2025

You've got 3 commits and only one is signed, hence Derek not removing the label.

You might try squashing the three into 1 and signing the remaining commit. Derek will remove the label when he's happy.

@alexellis
Copy link
Member

Hi,

Thanks for your interest in OpenFaaS.

  1. Our contribution guides are very clear - no work is to be submitted unless you create an issue first which is then approved by a maintainer.

  2. I appreciate you are skilled in Python unit testing, however we are no longer maintaining this workshop as other materials have superseded it and use more modern approaches.

Therefore I'm going to close the PR due to 1) and 2) combined.

If you'd like to write something separate on the openfaas blog about Python functions and/or unit testing then we'd be open to suggestions.

Alex

@alexellis alexellis closed this Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants