We are unable to run pytest locally to test anything because of issue listed in the ticket. The logic in the file was added to tests test_batch_starter.py's test_duplicate_job(). I undid that change since it's more important to test other tests. If we want to continue testing batch starter's duplicate job, we will need to revisit. I will create issue to capture that.
Because of new changes in tests/lambda_endpoints/conftest.py that checks which database server to run, it causes below issue. I undid lot of new changes in that file related to the issue. We will need to revisit and figure out how we want to resolve that.
Steps to reproduce the issue
run pytest command from sds-data-manager root path.
Expected behavior (What should happen)
run pytest command without issue
Actual behavior (What does happen)
/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/config/init.py:318: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: helpconfig, Hook: pytest_cmdline_parse
ImportError: no pq wrapper available.
Attempts made:
couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
couldn't import psycopg 'binary' implementation: No module named 'psycopg_binary'
couldn't import psycopg 'python' implementation: dlopen(/opt/homebrew/opt/libpq/lib/libpq.dylib, 0x0006): tried: '/opt/homebrew/opt/libpq/lib/libpq.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/libpq/lib/libpq.dylib' (no such file), '/opt/homebrew/opt/libpq/lib/libpq.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/opt/homebrew/Cellar/libpq/17.0_2/lib/libpq.5.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/libpq/17.0_2/lib/libpq.5.dylib' (no such file), '/opt/homebrew/Cellar/libpq/17.0_2/lib/libpq.5.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
config = pluginmanager.hook.pytest_cmdline_parse(
Traceback (most recent call last):
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/bin/pytest", line 8, in
sys.exit(console_main())
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/config/init.py", line 185, in console_main
code = main()
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/config/init.py", line 143, in main
config = _prepareconfig(args, plugins)
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/config/init.py", line 318, in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 501, in call
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 119, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 155, in _multicall
teardown[0].send(outcome)
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/helpconfig.py", line 100, in pytest_cmdline_parse
config: Config = outcome.get_result()
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/pluggy/_result.py", line 99, in get_result
raise exc.with_traceback(exc.traceback)
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 102, in _multicall
res = hook_impl.function(*args)
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/config/init.py", line 1003, in pytest_cmdline_parse
self.parse(args)
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/config/init.py", line 1283, in parse
self._preparse(args, addopts=addopts)
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/config/init.py", line 1172, in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 414, in load_setuptools_entrypoints
plugin = ep.load()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/metadata/init.py", line 171, in load
module = import_module(match.group('module'))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 170, in exec_module
exec(co, module.dict)
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/pytest_postgresql/plugin.py", line 23, in
from pytest_postgresql import factories
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 170, in exec_module
exec(co, module.dict)
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/pytest_postgresql/factories/init.py", line 20, in
from pytest_postgresql.factories.client import postgresql
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 170, in exec_module
exec(co, module.dict)
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/pytest_postgresql/factories/client.py", line 23, in
import psycopg
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/psycopg/init.py", line 9, in
from . import pq # noqa: F401 import early to stabilize side effects
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/psycopg/pq/init.py", line 114, in
import_from_libpq()
File "/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/psycopg/pq/init.py", line 106, in import_from_libpq
raise ImportError(
ImportError: no pq wrapper available.
Attempts made:
couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
couldn't import psycopg 'binary' implementation: No module named 'psycopg_binary'
couldn't import psycopg 'python' implementation: dlopen(/opt/homebrew/opt/libpq/lib/libpq.dylib, 0x0006): tried: '/opt/homebrew/opt/libpq/lib/libpq.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/libpq/lib/libpq.dylib' (no such file), '/opt/homebrew/opt/libpq/lib/libpq.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/opt/homebrew/Cellar/libpq/17.0_2/lib/libpq.5.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/libpq/17.0_2/lib/libpq.5.dylib' (no such file), '/opt/homebrew/Cellar/libpq/17.0_2/lib/libpq.5.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
Code Snippet:
Code
"""Setup testing environment to test lambda handler code."""
import subprocess
from unittest.mock import patch
import boto3
import pytest
from moto import mock_events, mock_s3
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sds_data_manager.lambda_code.SDSCode.database import database as db
from sds_data_manager.lambda_code.SDSCode.database.models import Base
BUCKET_NAME = "test-data-bucket"
@pytest.fixture(autouse=True)
def _set_env(monkeypatch):
"""Set global environment variables."""
monkeypatch.setenv("S3_BUCKET", BUCKET_NAME)
# Mock AWS Credentials for moto
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
monkeypatch.setenv("AWS_DEFAULT_REGION", "us-east-1")
@pytest.fixture(scope="module")
def science_file():
"""Path to a valid science file."""
return "imap/swe/l1a/2010/01/imap_swe_l1a_test-description_20100101_v000.cdf"
@pytest.fixture(scope="module")
def spice_file():
"""Path to a valid spice file."""
return "spice/ck/test_v000.bc"
@pytest.fixture(autouse=True, scope="module")
def s3_client():
"""Mock S3 Client, so we don't need network requests."""
with mock_s3():
s3_client = boto3.client("s3", region_name="us-east-1")
s3_client.create_bucket(
Bucket=BUCKET_NAME,
)
yield s3_client
@pytest.fixture()
def events_client():
"""Mock EventBridge client."""
with mock_events():
yield boto3.client("events", region_name="us-west-2")
# Check if postgres is available on the system. If it is returncode == 0
POSTGRES_AVAILABLE = (
subprocess.run("which psql", shell=True, check=False).returncode == 0
)
if POSTGRES_AVAILABLE:
@pytest.fixture()
def connection(postgresql):
"""Use a postgres connection string."""
return f"postgresql+psycopg://{postgresql.info.user}:@{postgresql.info.host}:{postgresql.info.port}/{postgresql.info.dbname}"
else:
@pytest.fixture()
def connection():
"""Fallback to sqlite in memory database."""
return "sqlite:///:memory:"
# NOTE: The default scope is function, so each test function will
# get a new database session and start fresh each time.
@pytest.fixture()
def session(connection):
"""Create a test postgres database engine."""
with patch.object(db, "Session") as mock_session:
engine = create_engine(connection)
# Create the tables and session
Base.metadata.create_all(engine)
with sessionmaker(bind=engine)() as session:
# Attach this session to the mocked module's Session call
mock_session.return_value = session
# Provide the session to the tests
yield session
# Cleanup after the test
session.rollback()
session.close()
# Drop tables to ensure clean state for next test
Base.metadata.drop_all(engine)
Additional notes, affected areas, and suggested fixes
Description of the issue
We are unable to run pytest locally to test anything because of issue listed in the ticket. The logic in the file was added to tests test_batch_starter.py's test_duplicate_job(). I undid that change since it's more important to test other tests. If we want to continue testing batch starter's duplicate job, we will need to revisit. I will create issue to capture that.
Because of new changes in
tests/lambda_endpoints/conftest.py
that checks which database server to run, it causes below issue. I undid lot of new changes in that file related to the issue. We will need to revisit and figure out how we want to resolve that.Steps to reproduce the issue
run
pytest
command from sds-data-manager root path.Expected behavior (What should happen)
run pytest command without issue
Actual behavior (What does happen)
/Users/tech3371/Library/Caches/pypoetry/virtualenvs/sds-data-manager-Be1fnlCS-py3.10/lib/python3.10/site-packages/_pytest/config/init.py:318: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown. Plugin: helpconfig, Hook: pytest_cmdline_parse ImportError: no pq wrapper available. Attempts made:
Code Snippet:
Additional notes, affected areas, and suggested fixes
No response