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
179 stars 19 forks source link

AttributeError: module 'sqlalchemy.dialects.sqlite.base' has no attribute 'JSON' using SQLAlchemy 1.2 #101

Closed ziazon closed 3 years ago

ziazon commented 3 years ago

Describe the bug Description of what the bug is.

Environment

To Reproduce Steps to reproduce the behavior:

  1. Use a project which business SQLAlchemy 1.2.19
  2. Install latest pytest mock resources
  3. create a simple test that simply assert True == True with no DB connection init.
  4. run pytest
  5. see error: AttributeError: module 'sqlalchemy.dialects.sqlite.base' has no attribute 'JSON'

Expected behavior the test passes

Actual Behavior

  File "/path/to/.venv/lib/python3.6/site-packages/pytest_mock_resources/fixture/database/__init__.py", line 4, in <module>
    from pytest_mock_resources.fixture.database.relational import (
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "/path/to/.venv/lib/python3.6/site-packages/_pytest/assertion/rewrite.py", line 171, in exec_module
    exec(co, module.__dict__)
  File "/path/to/.venv/lib/python3.6/site-packages/pytest_mock_resources/fixture/database/relational/__init__.py", line 5, in <module>
    from pytest_mock_resources.fixture.database.relational.sqlite import create_sqlite_fixture
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "/path/to/.venv/lib/python3.6/site-packages/_pytest/assertion/rewrite.py", line 171, in exec_module
    exec(co, module.__dict__)
  File "/path/to/.venv/lib/python3.6/site-packages/pytest_mock_resources/fixture/database/relational/sqlite.py", line 111, in <module>
    class PMRSQLiteDialect(SQLiteDialect_pysqlite):
  File "/path/to/.venv/lib/python3.6/site-packages/pytest_mock_resources/fixture/database/relational/sqlite.py", line 122, in PMRSQLiteDialect
    sqltypes.JSON: sqlite_base.JSON,
AttributeError: module 'sqlalchemy.dialects.sqlite.base' has no attribute 'JSON'

Additional context This is not an issue if I upgrade SQLAlchemy to 1.3.0.

DanCardin commented 3 years ago

Seems like 2 related issues:

  1. We should put a minimum bound of 1.3.0 on sqlalchemy. Currently it's unbounded, but the JSON attribute doesn't exist in i.e. 1.2.19 of sqlalchemy
  2. We really shouldnt be instrumenting sqlite upon module import, because it's gross, but also to enable not instrumenting it at all
DanCardin commented 3 years ago

Ought to be fixed as of 1.5.0