Skip to content

Commit

Permalink
👷 Add GitHub Actions workflow for running pytest
Browse files Browse the repository at this point in the history
- Set up GitHub Actions to automatically run `pytest` on pushes and pull requests for the `main` and `chore/pypi-release` branches.
- Configured a testing matrix to run tests on Python versions 3.7 through 3.11.
- Integrated dependency installation using `requirements.txt` or `pyproject.toml` (if present).
- Added steps to checkout code, set up Python environments, and run pytest with coverage.
  • Loading branch information
loureirorg committed Sep 19, 2024
1 parent d17196c commit d31360b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"GitHub.copilot-chat",
"mikestead.dotenv",
"ms-python.flake8",
"tamasfe.even-better-toml"
"tamasfe.even-better-toml",
"github.vscode-github-actions"
],
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run Tests

on: ['push', 'pull_request']

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest] # Define OS you want to test
python-version: [3.7, 3.11] # Define Python versions you want to test

name: P${{ matrix.python-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then pip install .[dev]; fi
- name: Run tests
run: |
pytest --cov # Run pytest with coverage if needed
16 changes: 16 additions & 0 deletions tests/test_middlewareable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@
from _pytest.capture import CaptureFixture
from python_middlewareable import MiddlewareableBase
from tests.stubs.fake_basic_middlewares import (
MiddlewareBase,
Request,
OneMiddleware,
TwoMiddleware,
)


@pytest.mark.asyncio
async def test_default_middleware():
class MyMiddleware(MiddlewareBase[Request]):
pass

class App(MiddlewareableBase[Request]):
middlewares = [MyMiddleware]

app = App()

result = await app.process_middlewares(Request(value="Hello"))

assert result.value == "Hello"


@pytest.mark.asyncio
async def test_basic_usage_instructions():
class App(MiddlewareableBase[Request]):
Expand Down

0 comments on commit d31360b

Please sign in to comment.