fix setuptools issue for python3.12 (#67)

* fix setuptools issue for python3.12

* one test file fot tests and ci
This commit is contained in:
Dmitry Afanasyev 2023-12-17 15:20:02 +03:00 committed by GitHub
parent 4e7ddf07fd
commit 4117a2f467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 22 additions and 49 deletions

View File

@ -65,7 +65,7 @@ jobs:
#---------------------------------------------- #----------------------------------------------
- name: Coverage report - name: Coverage report
run: | run: |
cp bot_microservice/settings/.env.ci.runtests bot_microservice/settings/.env cp bot_microservice/settings/.env.runtests bot_microservice/settings/.env
docker compose run bot poetry run bash -c "coverage run -m pytest -vv --exitfirst && poetry run coverage report" docker compose run bot poetry run bash -c "coverage run -m pytest -vv --exitfirst && poetry run coverage report"
#---------------------------------------------- #----------------------------------------------
# check dependencies # check dependencies

View File

@ -79,7 +79,7 @@ gunicorn main:create_app --workers 10 --bind 0.0.0.0:8000 --worker-class uvicorn
### Run local tests: ### Run local tests:
```bash ```bash
cd bot_microservice cd bot_microservice
LOCALTEST=1 STAGE=runtests poetry run pytest STAGE=runtests poetry run pytest
``` ```
### Run tests in docker compose: ### Run tests in docker compose:

View File

@ -1,23 +0,0 @@
STAGE="runtests"
# ==== start app settings ====
APP_HOST="0.0.0.0"
APP_PORT="8000"
DB_NAME="test_chatgpt.db"
# ==== telegram settings ====
TELEGRAM_API_TOKEN="123456789:AABBCCDDEEFFaabbccddeeff-1234567890"
# set to true to start with webhook. Else bot will start on polling method
START_WITH_WEBHOOK="false"
# ==== domain settings ====
DOMAIN="http://localhost"
URL_PREFIX=
CHAT_PREFIX="/chat"
# ==== gpt settings ====
GPT_BASE_HOST="http://localhost"
# ==== other settings ====
USER="web"

View File

@ -20,10 +20,7 @@ DIR_LOGS.mkdir(exist_ok=True)
env_path = f"{BASE_DIR}/settings/.env" env_path = f"{BASE_DIR}/settings/.env"
if environ.get("STAGE") == "runtests": if environ.get("STAGE") == "runtests":
if "LOCALTEST" in environ: env_path = f"{BASE_DIR}/settings/.env.runtests"
env_path = f"{BASE_DIR}/settings/.env.local.runtests"
else:
env_path = f"{BASE_DIR}/settings/.env.ci.runtests"
load_dotenv(env_path, override=True) load_dotenv(env_path, override=True)

View File

@ -3,9 +3,7 @@ from asyncio import AbstractEventLoop
from typing import Any, AsyncGenerator, Generator from typing import Any, AsyncGenerator, Generator
import pytest import pytest
import pytest_asyncio
from httpx import AsyncClient from httpx import AsyncClient
from pytest_asyncio.plugin import SubRequest
from sqlalchemy import Engine, create_engine from sqlalchemy import Engine, create_engine
from sqlalchemy.orm import Session, sessionmaker from sqlalchemy.orm import Session, sessionmaker
from telegram import Bot, User from telegram import Bot, User
@ -45,7 +43,7 @@ def engine(test_settings: AppSettings) -> Generator[Engine, None, None]:
engine.dispose() engine.dispose()
@pytest_asyncio.fixture(scope="function") @pytest.fixture()
def dbsession(engine: Engine) -> Generator[Session, None, None]: def dbsession(engine: Engine) -> Generator[Session, None, None]:
""" """
Get session to database. Get session to database.
@ -150,7 +148,7 @@ def _get_bot_user(token: str) -> User:
# Redefine the event_loop fixture to have a session scope. Otherwise `bot` fixture can't be # Redefine the event_loop fixture to have a session scope. Otherwise `bot` fixture can't be
# session. See https://github.com/pytest-dev/pytest-asyncio/issues/68 for more details. # session. See https://github.com/pytest-dev/pytest-asyncio/issues/68 for more details.
@pytest.fixture(scope="session", autouse=True) @pytest.fixture(scope="session", autouse=True)
def event_loop(request: SubRequest) -> AbstractEventLoop: def event_loop() -> AbstractEventLoop:
""" """
Пересоздаем луп для изоляции тестов. В основном нужно для запуска юнит тестов Пересоздаем луп для изоляции тестов. В основном нужно для запуска юнит тестов
в связке с интеграционными, т.к. без этого pytest зависает. в связке с интеграционными, т.к. без этого pytest зависает.
@ -166,7 +164,7 @@ def bot_info() -> dict[str, Any]:
return BotInfoFactory() return BotInfoFactory()
@pytest_asyncio.fixture(scope="session") @pytest.fixture(scope="session")
async def bot_application(bot_info: dict[str, Any]) -> AsyncGenerator[Any, None]: async def bot_application(bot_info: dict[str, Any]) -> AsyncGenerator[Any, None]:
# We build a new bot each time so that we use `app` in a context manager without problems # We build a new bot each time so that we use `app` in a context manager without problems
application = ApplicationBuilder().bot(make_bot(bot_info)).application_class(PytestApplication).build() application = ApplicationBuilder().bot(make_bot(bot_info)).application_class(PytestApplication).build()
@ -177,7 +175,7 @@ async def bot_application(bot_info: dict[str, Any]) -> AsyncGenerator[Any, None]
await application.shutdown() await application.shutdown()
@pytest_asyncio.fixture(scope="session") @pytest.fixture(scope="session")
async def bot(bot_info: dict[str, Any], bot_application: Any) -> AsyncGenerator[PytestExtBot, None]: async def bot(bot_info: dict[str, Any], bot_application: Any) -> AsyncGenerator[PytestExtBot, None]:
"""Makes an ExtBot instance with the given bot_info""" """Makes an ExtBot instance with the given bot_info"""
async with make_bot(bot_info) as _bot: async with make_bot(bot_info) as _bot:
@ -185,7 +183,7 @@ async def bot(bot_info: dict[str, Any], bot_application: Any) -> AsyncGenerator[
yield _bot yield _bot
@pytest_asyncio.fixture(scope="session") @pytest.fixture(scope="session")
async def main_application( async def main_application(
bot_application: PytestApplication, test_settings: AppSettings bot_application: PytestApplication, test_settings: AppSettings
) -> AsyncGenerator[AppApplication, None]: ) -> AsyncGenerator[AppApplication, None]:
@ -203,7 +201,7 @@ async def main_application(
await database.drop_database() await database.drop_database()
@pytest_asyncio.fixture() @pytest.fixture()
async def rest_client(main_application: AppApplication) -> AsyncGenerator[AsyncClient, None]: async def rest_client(main_application: AppApplication) -> AsyncGenerator[AsyncClient, None]:
""" """
Default http client. Use to test unauthorized requests, public endpoints Default http client. Use to test unauthorized requests, public endpoints

View File

@ -59,7 +59,9 @@ COPY ./scripts/start-bot.sh /app/
RUN chmod +x ./start-bot.sh RUN chmod +x ./start-bot.sh
COPY --from=compile-image /app/.venv /app/.venv COPY --from=compile-image /app/.venv /app/.venv
ENV PATH="/app/.venv/bin:$PATH"
# workarroud fo python3.12 and setuptools not found for fastapi users
RUN pip3 uninstall -y setuptools && pip3 install --upgrade setuptools wheel
USER ${USER} USER ${USER}
ENV PATH="/app/.venv/bin:$PATH"

17
poetry.lock generated
View File

@ -2748,21 +2748,20 @@ testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "no
[[package]] [[package]]
name = "pytest-asyncio" name = "pytest-asyncio"
version = "0.23.2" version = "0.15.1"
description = "Pytest support for asyncio" description = "Pytest support for asyncio."
optional = false optional = false
python-versions = ">=3.8" python-versions = ">= 3.6"
files = [ files = [
{file = "pytest-asyncio-0.23.2.tar.gz", hash = "sha256:c16052382554c7b22d48782ab3438d5b10f8cf7a4bdcae7f0f67f097d95beecc"}, {file = "pytest-asyncio-0.15.1.tar.gz", hash = "sha256:2564ceb9612bbd560d19ca4b41347b54e7835c2f792c504f698e05395ed63f6f"},
{file = "pytest_asyncio-0.23.2-py3-none-any.whl", hash = "sha256:ea9021364e32d58f0be43b91c6233fb8d2224ccef2398d6837559e587682808f"}, {file = "pytest_asyncio-0.15.1-py3-none-any.whl", hash = "sha256:3042bcdf1c5d978f6b74d96a151c4cfb9dcece65006198389ccd7e6c60eb1eea"},
] ]
[package.dependencies] [package.dependencies]
pytest = ">=7.0.0" pytest = ">=5.4.0"
[package.extras] [package.extras]
docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"] testing = ["coverage", "hypothesis (>=5.7.1)"]
testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)"]
[[package]] [[package]]
name = "pytest-clarity" name = "pytest-clarity"
@ -4003,4 +4002,4 @@ multidict = ">=4.0"
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.12" python-versions = "^3.12"
content-hash = "0da89addadf785cd04e9b7bd9c16355c8fa3f6d2f9b0336e100db5717b1c0646" content-hash = "382d826bbe0346cfd327c9729de156623d7efc916dbf4af18bd51a2cfc0d5e13"

View File

@ -58,7 +58,7 @@ types-PyMySQL = "^1.0"
types-python-dateutil = "^2.8" types-python-dateutil = "^2.8"
pytest = "^7.4" pytest = "^7.4"
pytest-asyncio = "^0.23" pytest-asyncio = "^0.15.1"
pytest-deadfixtures = "^2.2" pytest-deadfixtures = "^2.2"
pytest-repeat = "^0.9" pytest-repeat = "^0.9"
pytest-testmon = "^2.1" pytest-testmon = "^2.1"