CloverHealth / pytest-pgsql

Clean PostgreSQL Databases for Your Tests
http://pytest-pgsql.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
65 stars 4 forks source link

Incompatible usage of abcmeta for python 2.7 #4

Closed goetzk closed 6 years ago

goetzk commented 6 years ago

Hi, I'm giving pytest-pgsql a try (thanks!) but when I try and run it there appears to be some code that is not python 2.7 compatible.

# pytest --durations=4 --cov --pg-extensions=postgis
Traceback (most recent call last):
  File "/usr/local/bin/pytest", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 49, in main
    config = _prepareconfig(args, plugins)
  File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 168, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 613, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 250, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "/usr/local/lib/python2.7/dist-packages/_pytest/helpconfig.py", line 68, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 280, in get_result
    _reraise(*ex)  # noqa
  File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 265, in __init__
    self.result = func()
  File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 957, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 1121, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 1084, in _preparse
    self.pluginmanager.load_setuptools_entrypoints('pytest11')
  File "/usr/local/lib/python2.7/dist-packages/_pytest/vendored_packages/pluggy.py", line 510, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2408, in load
    return self.resolve()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2414, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python2.7/dist-packages/pytest_pgsql/__init__.py", line 5, in <module>
    from pytest_pgsql.database import PostgreSQLTestDBBase
  File "/usr/local/lib/python2.7/dist-packages/pytest_pgsql/database.py", line 51
    class PostgreSQLTestDBBase(metaclass=abc.ABCMeta):
                                        ^
SyntaxError: invalid syntax

See here for a pre existing discussion about this problem: https://stackoverflow.com/questions/35673474/using-abc-abcmeta-in-a-way-it-is-compatible-both-with-python-2-7-and-python-3-5

Package install:

# pip install pytest-pgsql
Collecting pytest-pgsql
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading pytest-pgsql-1.0.4.tar.gz (40kB)
    100% |████████████████████████████████| 40kB 937kB/s 
Collecting freezegun>=0.3.6 (from pytest-pgsql)
  Downloading freezegun-0.3.9-py2.py3-none-any.whl
Collecting pytest<3.3,>=3.0 (from pytest-pgsql)
  Downloading pytest-3.2.5-py2.py3-none-any.whl (188kB)
    100% |████████████████████████████████| 194kB 802kB/s 
Collecting sqlalchemy>=1.1.0 (from pytest-pgsql)
  Downloading SQLAlchemy-1.2.2.tar.gz (5.5MB)
    100% |████████████████████████████████| 5.5MB 97kB/s 
Collecting testing.postgresql>=1.3.0 (from pytest-pgsql)
  Downloading testing.postgresql-1.3.0-py2.py3-none-any.whl
Requirement already satisfied: python-dateutil!=2.0,>=1.0 in /usr/local/lib/python2.7/dist-packages (from freezegun>=0.3.6->pytest-pgsql)
Requirement already satisfied: six in /usr/local/lib/python2.7/dist-packages (from freezegun>=0.3.6->pytest-pgsql)
Requirement already satisfied: setuptools in /usr/local/lib/python2.7/dist-packages (from pytest<3.3,>=3.0->pytest-pgsql)
Requirement already satisfied: py>=1.4.33 in /usr/local/lib/python2.7/dist-packages (from pytest<3.3,>=3.0->pytest-pgsql)
Collecting pg8000>=1.10 (from testing.postgresql>=1.3.0->pytest-pgsql)
  Downloading pg8000-1.11.0-py2.py3-none-any.whl
Collecting testing.common.database (from testing.postgresql>=1.3.0->pytest-pgsql)
  Downloading testing.common.database-2.0.3-py2.py3-none-any.whl
Building wheels for collected packages: pytest-pgsql, sqlalchemy
  Running setup.py bdist_wheel for pytest-pgsql ... done
  Stored in directory: /root/.cache/pip/wheels/eb/3f/af/dd33b5d09d26b52a71330c1d4ec9b7957c39c33184717e1c53
  Running setup.py bdist_wheel for sqlalchemy ... done
  Stored in directory: /root/.cache/pip/wheels/1a/82/00/91a123a38de796ba3e559f837be5ac5d429afe5c7cd3ef2220
Successfully built pytest-pgsql sqlalchemy
Installing collected packages: freezegun, pytest, sqlalchemy, pg8000, testing.common.database, testing.postgresql, pytest-pgsql
  Found existing installation: pytest 3.3.2
    Uninstalling pytest-3.3.2:
      Successfully uninstalled pytest-3.3.2
Successfully installed freezegun-0.3.9 pg8000-1.11.0 pytest-3.2.5 pytest-pgsql-1.0.4 sqlalchemy-1.2.2 testing.common.database-2.0.3 testing.postgresql-1.3.0
dargueta commented 6 years ago

This library was never intended to be compatible with Python 2. I'm actually surprised that pip let you install it since we set requires-python in the metadata here. Sorry about that!

@wesleykendall based on this bug report I think we're supposed to use python-requires not requires-python. I fixed this and also added a manual check for versions of pip older than 9.0.

PR: https://github.com/CloverHealth/pytest-pgsql/pull/5

goetzk commented 6 years ago

Thanks for the quick response.

I was surprised it installed too, but I tried because despite pypi listing the 'Py version' as 3 and the install example being 'pip3 install', the page also has 'requires distribution' of 'pytest (<3.3,>=3.0); (python_version<"3.4")'.

https://pypi.python.org/pypi/pytest-pgsql

I guess I'll come back to pytest-pgsql when the codebase I'm working on is python 3 aware!

wesleykendall commented 6 years ago

Fixed in https://github.com/CloverHealth/pytest-pgsql/pull/5