wonderful-boots-93625
02/16/2023, 7:34 PMpytest_psql
when running tests within the pex sandbox:
/Users/nasron/.cache/pants/named_caches/pex_root/venvs/s/e101a3aa/venv/lib/python3.8/site-packages/pytest_pgsql/plugin.py:88: in database_snapshot
return database.create_database_snapshot(pg_engine)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
connectable = Engine(<postgresql://postgres@127.0.0.1:63347/test>)
def create_database_snapshot(connectable):
"""Create a snapshot of the current state of the database so that we can
restore it to this state when the test exits.
Arguments:
connectable (`sqlalchemy.engine.Connectable`):
The engine, connection, or other Connectable to use to take this
snapshot.
Returns (dict):
A dictionary with three keys:
* ``schemas``: A tuple of the names of all the schemas present.
* ``tables``: A list of all of the tables present. Each item in the list
is a dictionary with the schema name, table name, and table OID.
* ``extensions``: A tuple of the names of all the extensions currently
installed.
"""
> execute = connectable.execute
E AttributeError: 'Engine' object has no attribute 'execute'
I think pyscopg2-binary
isn’t getting installed despite being in the dependency list - but I’m note sure.tall-battery-32825
02/16/2023, 8:22 PMpsycopg2-binary
to your test targets? The following is a snippet from my project/tests/BUILD
file. The same directory which has my conftest.py
file:
python_test_utils(
name="test_utils",
dependencies=[
"//:monorepodeps#psycopg2-binary",
"//:monorepodeps#python-multipart",
"//:app-env",
],
)
I had to explicitly add the dependency to my test_utils target. Hope this helps!wonderful-boots-93625
02/16/2023, 8:42 PMpyscopg2
because pants dependencies
indicates it’s there
$ ./pants dependencies --transitive iai_fl_gateway/tests:tests | grep psy
3rdparty:reqs#psycopg2-binary
broad-processor-92400
02/16/2023, 8:56 PMimport psycopg2
doesn't work?
If you haven't seen it before, https://www.pantsbuild.org/docs/python-test-goal#debugging-tests discusses a few ways to attach a debugger to be able to check these things.wonderful-boots-93625
02/16/2023, 10:21 PMwonderful-boots-93625
02/17/2023, 9:26 PM[pytest]
version = 'pytest==7.2.1'
extra_requirements = [
'SQLAlchemy[mypy]==1.4.46', # to match 3rdparty/all_requirements.txt
'pytest-cov',
'pytest-env',
'pytest-pgsql',
'pytest-xdist'
]
lockfile='pytest.lock'
I had to add the SQLAlchemy requirement there otherwise it installs version 2 (for some reason) which is incompatible with pytest-pqsql
There may be other libs that are conflicting with the ones in my 3rdparty/all_requirements.txt as well…broad-processor-92400
02/19/2023, 2:31 AM