From cdc85ba280e356eea1ca9eb490496cbd1a9af222 Mon Sep 17 00:00:00 2001 From: WrldEngine Date: Fri, 20 Jun 2025 15:00:23 +0500 Subject: [PATCH] hotfix: tests for python 3.8 --- tests/test_bsonjs_response_class.py | 35 +++++++++++++---------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/tests/test_bsonjs_response_class.py b/tests/test_bsonjs_response_class.py index 2e853f904..a1affaf68 100644 --- a/tests/test_bsonjs_response_class.py +++ b/tests/test_bsonjs_response_class.py @@ -1,33 +1,28 @@ import json +import pytest +import sys -# Because of python 3.8 doesn't support this library -try: - import bsonjs # type: ignore -except ImportError: # pragma: nocover - bsonjs = None -from fastapi import FastAPI -from fastapi.responses import BSONJSResponse -from fastapi.testclient import TestClient - -app = FastAPI(default_response_class=BSONJSResponse) - - -@app.get("/bsonjs_keys") -def get_bsonjs_serialized_data(): - return {"key": "Hello World", 1: 1} +@pytest.mark.skipif( + sys.version_info < (3, 9), reason="requires minimum python3.9 or higher" +) +def test_bsonjs_serialized_data(): + import bsonjs + from fastapi import FastAPI + from fastapi.responses import BSONJSResponse + from fastapi.testclient import TestClient -client = TestClient(app) + app = FastAPI(default_response_class=BSONJSResponse) + @app.get("/bsonjs_keys") + def get_bsonjs_serialized_data(): + return {"key": "Hello World"} -def test_bsonjs_serialized_data(): + client = TestClient(app) with client: response = client.get("/bsonjs_keys") - if bsonjs is not None: assert response.content == bsonjs.loads( json.dumps({"key": "Hello World", 1: 1}) ) - - assert True