schireson / pytest-mock-resources

Pytest Fixtures that let you actually test against external resource (Postgres, Mongo, Redshift...) dependent code.
https://pytest-mock-resources.readthedocs.io/en/latest/quickstart.html
MIT License
183 stars 19 forks source link

Engine CM causes patched methods to no longer be patched #45

Closed kpitzen closed 3 years ago

kpitzen commented 5 years ago

Describe the bug When using a context manager (eg with connection.redshift_engine.begin() as redshift_connection:, the copy redshift function is no longer patched into the psycopg2 engine.

Environment All

To Reproduce Steps to reproduce the behavior: Open a context managed redshift connection: with connection.redshift_engine.begin() as redshift_connection: execute a redshift copy statement with non-postgres syntax (include a credentials argument, for example)

Expected behavior The copy statement is executed, and the data from the source appears in the destination.

Actual Behavior

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x11f63d240>
cursor = <cursor object at 0x11ebf6238; closed: -1>
statement = "copy automri_assignment\n                        from 's3://xxx/xxx...asnull\n                        ignoreblanklines\n                        trimblanks;\n                        commit;"
parameters = {}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x11e93a978>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       psycopg2.errors.SyntaxError: syntax error at or near "credentials"
E       LINE 3:                         credentials 'aws_access_key_id=xxx...
E                                       ^

Additional context Feel free to reach out for more context if needed!

DanCardin commented 4 years ago

Added failing test in https://github.com/schireson/pytest-mock-resources/pull/86, fix maybe incoming

DanCardin commented 3 years ago

I'm not sure at which point the xfail on the linked test got removed, but it is removed, so i'm reasonably certain this is fixed.