Skip to content

Can't get tests to pass locally #346

@nsshah1288

Description

@nsshah1288

Hi, I do my development on an ec2 instance with an amazon linux 2023 image.

Here are some details about my system:
$ uname -a
Linux ec2.internal amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Oct 7 15:53:25 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

$ docker --version
Docker version 25.0.13, build 0bab007

$ docker compose version
Docker Compose version v2.30.3

When I ran uv sync and uv run pytest, I realized I needed a lot of system packages to be installed on my ec2 in order for the tests to pass. I installed libpq, libpq-devel, and postgresql-server to get past initial errors, but then I realized installing postgis on an amazon linux 2023 is quite difficult.

I then turned to the Dockerfile.tests and did the following:
docker compose run --build --rm tests python -m pytest -s -vv /app/tests/api/test_api.py

Here is a sample of the output:
platform linux -- Python 3.13.11, pytest-8.4.2, pluggy-1.6.0 -- /usr/local/bin/python
cachedir: .pytest_cache
rootdir: /app
configfile: pyproject.toml
plugins: anyio-4.12.1, postgresql-7.0.2, cov-7.0.0, asyncio-1.2.0
asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 482 items

tests/api/test_api.py::test_default_app_no_transactions[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_default_app_no_transactions[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_post_search_content_type[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_post_search_content_type[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_get_search_content_type[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_get_search_content_type[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_landing_links[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_landing_links[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_get_queryables_content_type[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_get_queryables_content_type[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_get_features_content_type[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_get_features_content_type[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_get_features_self_link[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_get_features_self_link[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_get_feature_content_type[api_client0-0.8.6] FAILED
tests/api/test_api.py::test_get_feature_content_type[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_api_headers[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_api_headers[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_core_router[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_core_router[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_landing_page_stac_extensions[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_landing_page_stac_extensions[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_transactions_router[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_transactions_router[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_app_transaction_extension[api_client0-0.8.6] PASSED
tests/api/test_api.py::test_app_transaction_extension[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_app_query_extension[api_client0-0.8.6] FAILED
tests/api/test_api.py::test_app_query_extension[api_client0-0.9.8] PASSED
tests/api/test_api.py::test_app_query_extension_limit_1[api_client0-0.8.6] FAILED

Many of the tests, just for pgstac version 0.8.6, are failing. Here are logs from one test failure:

===================================================== FAILURES ======================================================
_________________________________ test_get_feature_content_type[api_client0-0.8.6] __________________________________

app_client = <httpx.AsyncClient object at 0x7fc93715cc50>
load_test_collection = {'description': 'Landat 8 imagery radiometrically calibrated and orthorectified using gound points and Digital Elevation Model (DEM) data to correct relief displacement.', 'extent': {'spatial': {'bbox': [[-180.0, -90.0, 180.0, 90.0]]}, 'temporal': {'interval': [['2013-06-01T00:00:00Z', None]]}}, 'id': 'test-collection', 'keywords': ['landsat', 'earth observation', 'usgs'], ...}
load_test_item = {'assets': {'ANG': {'description': 'Collection 2 Level-1 Angle Coefficients File (ANG)', 'href': 'https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2021/108/066/LC08_L2SP_108066_20210712_20210720_02_T1/LC08_L2SP_108066_20210712_20210720_02_T1_ANG.txt', 'title': 'Angle Coefficients File', 'type': 'text/plain'}, 'MTL.txt': {'description': 'Collection 2 Level-1 Product Metadata File (MTL)', 'href': 'https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2021/108/066/LC08_L2SP_108066_20210712_20210720_02_T1/LC08_L2SP_108066_20210712_20210720_02_T1_MTL.txt', 'title': 'Product Metadata File', 'type': 'text/plain'}, 'MTL.xml': {'description': 'Collection 2 Level-1 Product Metadata File (xml)', 'href': 'https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2021/108/066/LC08_L2SP_108066_20210712_20210720_02_T1/LC08_L2SP_108066_20210712_20210720_02_T1_MTL.xml', 'title': 'Product Metadata File (xml)', 'type': 'application/xml'}, 'SR_B1': {'description': 'Collection 2 Level-2 Coastal/Aerosol Band (B1) Surface Reflectance', 'eo:bands': [{'center_wavelength': 0.44, 'common_name': 'coastal', 'full_width_half_max': 0.02, 'gsd': 30, ...}], 'gsd': 30, 'href': 'https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2021/108/066/LC08_L2SP_108066_20210712_20210720_02_T1/LC08_L2SP_108066_20210712_20210720_02_T1_SR_B1.TIF', ...}, ...}, 'bbox': [149.57574, -34.25796, 152.15194, -32.07915], 'collection': 'test-collection', 'geometry': {'coordinates': [[[152.15052873427666, -33.82243006904891], [150.1000346138806, -34.257132625788756], [149.5776607193635, -32.514709769700254], [151.6262528041627, -32.08081674221862], [152.15052873427666, -33.82243006904891]]], 'type': 'Polygon'}, ...}

async def test_get_feature_content_type(app_client, load_test_collection, load_test_item):
    resp = await app_client.get(
        f"collections/{load_test_collection['id']}/items/{load_test_item['id']}"
    )
  assert resp.headers["content-type"] == "application/geo+json"

E AssertionError: assert 'application/json' == 'application/geo+json'
E
E - application/geo+json
E ? ----
E + application/json

tests/api/test_api.py:133: AssertionError
------------------------------------------------- Captured log call -------------------------------------------------
ERROR stac_fastapi.api.errors:errors.py:62 Item test-item in Collection test-collection does not exist.
NoneType: None

It seems that for pgstac version 0.8.6, the test-item is not getting loaded properly in the DB? I am using the Dockerfile.tests and all code currently on the main branch, with no changes.

I saw that the github action that runs the test are successfully running all the tests, but I have been unable to reproduce the flow that happens in the test job in .github/workflows/cicd.yaml exactly on my ec2 instance. Could you please advise how I can get all the tests to pass locally? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions