From 029c45f8c257984ff77c4d7f5631fba57fb4b566 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 1 Jan 2022 22:57:51 -0800 Subject: [PATCH 1/2] TST: Clean pg8000 test --- .pre-commit-config.yaml | 6 ++++++ pandas/tests/io/test_sql.py | 12 ++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7bc0e1ca62ff3..854b7b2e4fe63 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -175,3 +175,9 @@ repos: entry: python scripts/pandas_errors_documented.py language: python files: ^pandas/errors/__init__.py$ + - id: pg8000-not-installed-CI + name: Check for pg8000 not installed on CI for test_pg8000_sqlalchemy_passthrough_error + language: pygrep + entry: 'pg8000' + files: ^ci/deps + types: [yaml] diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index c1007a01a3829..a8c80c2a3428e 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -1423,16 +1423,12 @@ def test_database_uri_string(self, test_frame1): tm.assert_frame_equal(test_frame1, test_frame3) tm.assert_frame_equal(test_frame1, test_frame4) - # using driver that will not be installed on Travis to trigger error + def test_pg8000_sqlalchemy_passthrough_error(self): + # using driver that will not be installed on CI to trigger error # in sqlalchemy.create_engine -> test passing of this error to user - try: - # the rest of this test depends on pg8000's being absent - import pg8000 # noqa:F401 - - pytest.skip("pg8000 is installed") - except ImportError: - pass + pytest.importorskip("pg8000") + # the rest of this test depends on pg8000's being absent db_uri = "postgresql+pg8000://user:pass@host/dbname" with pytest.raises(ImportError, match="pg8000"): sql.read_sql("select * from table", db_uri) From 781892b390c5beaab2b5643caa826d359be1b256 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sun, 2 Jan 2022 10:29:02 -0800 Subject: [PATCH 2/2] Fix mod import logic --- pandas/tests/io/test_sql.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index a8c80c2a3428e..7a94797543519 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -31,6 +31,8 @@ import numpy as np import pytest +import pandas.util._test_decorators as td + from pandas.core.dtypes.common import ( is_datetime64_dtype, is_datetime64tz_dtype, @@ -1423,12 +1425,10 @@ def test_database_uri_string(self, test_frame1): tm.assert_frame_equal(test_frame1, test_frame3) tm.assert_frame_equal(test_frame1, test_frame4) + @td.skip_if_installed("pg8000") def test_pg8000_sqlalchemy_passthrough_error(self): # using driver that will not be installed on CI to trigger error # in sqlalchemy.create_engine -> test passing of this error to user - pytest.importorskip("pg8000") - - # the rest of this test depends on pg8000's being absent db_uri = "postgresql+pg8000://user:pass@host/dbname" with pytest.raises(ImportError, match="pg8000"): sql.read_sql("select * from table", db_uri)