-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DEV-19025: nox * DEV-19025: nox * DEV-19025: nox * DEV-19025: codestyle * [DEV-19025]: framework versions tests * [DEV-19025]: testpaths * DEV-19025: codestyle
- Loading branch information
1 parent
9014c7e
commit f4223a7
Showing
5 changed files
with
130 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,19 @@ jobs: | |
- name: Run Tests | ||
run: pdm run pytest | ||
|
||
test_frameworks_compability: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [ '3.11.7' ] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up nox | ||
uses: wntrblm/[email protected] | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Run nox | ||
run: nox | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import nox | ||
|
||
DEPENDENCIES = [".", "pytest", "pytest_asyncio", "httpx"] | ||
|
||
|
||
@nox.session() | ||
@nox.parametrize("fastapi_version", ["0.66", "0.115.8"]) | ||
def test_fastapi_versions(session, fastapi_version): | ||
session.install(*DEPENDENCIES, f"fastapi=={fastapi_version}") | ||
session.run("pytest", "tests", "--framework=fastapi", "-k", "test_frameworks") | ||
|
||
|
||
@nox.session() | ||
@nox.parametrize("litestar_version", ["2.13.0", "2.14.0"]) | ||
def test_litestar_versions(session, litestar_version): | ||
session.install(*DEPENDENCIES, f"litestar=={litestar_version}") | ||
session.run("pytest", "tests", "--framework=litestar", "-k", "test_frameworks") | ||
|
||
|
||
@nox.session() | ||
@nox.parametrize("aiohttp_version", ["3.9.1", "3.11.12"]) | ||
def test_aiohttp_versions(session, aiohttp_version): | ||
session.install(*DEPENDENCIES, f"aiohttp=={aiohttp_version}") | ||
session.run("pytest", "tests", "--framework=aiohttp", "-k", "test_frameworks") |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from enum import Enum | ||
from typing import TYPE_CHECKING, Callable, Dict, Optional, Sequence, Union | ||
|
||
import pytest | ||
|
||
if TYPE_CHECKING: | ||
from aiohttp.test_utils import TestClient as AiohttpTestClient | ||
from httpx import AsyncClient as HttpxClient | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption("--framework", action="store", help="run with framework") | ||
|
||
|
||
def pytest_generate_tests(metafunc): | ||
if "framework" in metafunc.fixturenames: | ||
if metafunc.config.getoption("framework"): | ||
frameworks = [metafunc.config.getoption("framework")] | ||
else: | ||
frameworks = ["fastapi", "aiohttp", "litestar"] | ||
metafunc.parametrize("framework", frameworks) | ||
|
||
|
||
class Framework(str, Enum): | ||
aiohttp = "aiohttp" | ||
fastapi = "fastapi" | ||
litestar = "litestar" | ||
|
||
|
||
APP_FACTORIES: Dict[Framework, Optional[Callable]] = { | ||
Framework.fastapi: None, | ||
Framework.aiohttp: None, | ||
Framework.litestar: None, | ||
} | ||
|
||
|
||
def app_factory(framework: Framework): | ||
factory = APP_FACTORIES[framework] | ||
if factory: | ||
return factory | ||
|
||
if framework == Framework.aiohttp: | ||
from tests.test_web_frameworks.aiohttp import aiohttp_app | ||
|
||
APP_FACTORIES[framework] = aiohttp_app | ||
elif framework == Framework.fastapi: | ||
from tests.test_web_frameworks.fastapi import fastapi_app | ||
|
||
APP_FACTORIES[framework] = fastapi_app | ||
else: | ||
from tests.test_web_frameworks.litestar import litestar_app | ||
|
||
APP_FACTORIES[framework] = litestar_app | ||
|
||
return APP_FACTORIES[framework] | ||
|
||
|
||
@pytest.fixture | ||
async def create_app(framework): | ||
factory = app_factory(framework) | ||
aiohttp_client = None | ||
|
||
async def create_application( | ||
include_routes: Optional[Sequence[str]] = None, | ||
exclude_routes: Optional[Sequence[str]] = None, | ||
) -> Union["AiohttpTestClient", "HttpxClient"]: | ||
client = factory(include_routes=include_routes, exclude_routes=exclude_routes) | ||
if framework == Framework.aiohttp: | ||
# For aiohttp client implementation we need to start and stop server | ||
nonlocal aiohttp_client | ||
aiohttp_client = client | ||
await client.start_server() | ||
return client | ||
|
||
yield create_application | ||
|
||
if aiohttp_client: | ||
await aiohttp_client.close() |
This file contains 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