Closed pliniozanini closed 1 year ago
Released fix for this in 2.6.1. Thanks for the report!
Thank you, @DanCardin, for the quick response!
However, I noticed we still have a problem when trying to use the same example:
When using db = create_redshift_fixture(session=True)
, it works fine, nonetheless, when using db = create_redshift_fixture(session=False)
, the following error appears:
============================================================ test session starts =============================================================
platform linux -- Python 3.9.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /home/zanini/repo/RecSys/.venv/bin/python
cachedir: .pytest_cache
rootdir: /home/zanini/repo/RecSys, configfile: tox.ini
plugins: mock-resources-2.6.1, mock-3.10.0, xdist-1.34.0, postgresql-4.1.1, cov-2.12.1, forked-1.4.0, anyio-3.6.2
collected 1 item
tests/test_temp.py::test_sql_sum === <class 'sqlalchemy.engine.base.Engine'>
FAILED
================================================================== FAILURES ==================================================================
________________________________________________________________ test_sql_sum ________________________________________________________________
db = Engine(postgresql+psycopg2://user:***@localhost:5532/pytest_mock_resource_db_1?sslmode=disable)
def test_sql_sum(db):
> sql_sum(db)
tests/test_temp.py:14:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
util/temp.py:5: in sql_sum
redshift_conn.execute("CREATE TEMP TABLE mytemp(c INT);")
<string>:2: in execute
???
../.venv/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py:402: in warned
return fn(*args, **kwargs)
../.venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py:3257: in execute
return connection.execute(statement, *multiparams, **params)
../.venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py:1365: in execute
return self._exec_driver_sql(
../.venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py:1669: in _exec_driver_sql
ret = self._execute_context(
../.venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py:1842: in _execute_context
statement, parameters = fn(
../.venv/lib/python3.9/site-packages/pytest_mock_resources/patch/redshift/sqlalchemy.py:54: in receive_before_cursor_execute
normalized_statement = strip(statement).lower()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
input_string = <sqlalchemy.sql.elements.TextClause object at 0x7fd3db9461f0>
def strip(input_string):
"""Strip trailing whitespace, single/double quotes."""
> return input_string.strip().rstrip(";").strip('"').strip("'")
E AttributeError: 'TextClause' object has no attribute 'strip'
../.venv/lib/python3.9/site-packages/pytest_mock_resources/patch/redshift/mock_s3_copy.py:189: AttributeError
========================================================== short test summary info ===========================================================
FAILED tests/test_temp.py::test_sql_sum - AttributeError: 'TextClause' object has no attribute 'strip'
============================================================= 1 failed in 8.57s ==============================================================
I noticed the error I reported previously was also exclusive from the session=True
case.
@pliniozanini I dont suppose you'd mind checking out this branch https://github.com/schireson/pytest-mock-resources/pull/172 and testing to see if it solves your issue? I added tests of both sides and now don't see either issue
Just released 2.6.3 which hopefully fixes both directions of issue? We at least have some tests in either direction, so it should be a net-different issue if you're still encountering problems hopefully.
Feel free to keep commenting here if you do, and i can re-open again! Thanks!
Describe the bug Description of what the bug is.
Environment
To Reproduce Trying to reproduce the example given
tests/test.temp.py:
src/util/temp.py:
Expected behavior Test to be concluded successfully
Actual Behavior
Additional context I managed to fix the issue by noticing the event "before_execute" and the event in the following call "before_cursor_execute" are core events the should be called by a connection.
Changing
register_redshift_behavior
inpytest_mock_resources/patch/redshift/sqlalchemy.py
to
solved the problem, since it was passing a sqlalchemy.orm.session.Session object instead of a connection one
Not sure if that was due to some issues on my system, since that is the main code I assume other have previously used with no problem.