Repository: pandas-dev/pandas

Issue:
TST: psycopg2 errors when running tests locally
I just started noticing these (167 of them) in the logs from `python -m pytest pandas/tests --skip-slow`

```
_____________________________ ERROR at setup of TestPostgreSQLAlchemyConn.test_read_sql[load_iris_data0] ______________________________

cls = <pandas.tests.io.test_sql.TestPostgreSQLAlchemyConn object at 0x7f2843ab4a50>

    @pytest.fixture(autouse=True, scope='class')
    def setup_class(cls):
        cls.setup_import()
        cls.setup_driver()
        conn = cls.connect()
>       conn.connect()

[...]
>       conn = _connect(dsn, connection_factory=connection_factory, async=async)
E       OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied

../../.local/lib/python2.7/site-packages/psycopg2/__init__.py:164: OperationalError
```


Discussion:
Looking at setup.cfg, I guess I'm supposed to start specifying `--skip-db` too?
Skipping should probably be the default, right @datapythonista?
I thought about it, but as `pymysql` and `psycopg` are not in `environment.yml`, I didn't see a difference, as the tests should be skipped anyway.

Happy to change it, I don't have a preference.
I'd prefer skipping but default (but failing if the db tests are requested
and don't get setup correctly). I know that I have pyscopg2 installed in my
dev env, but don't have the expected databases setup right now.

On Sat, Dec 29, 2018 at 2:19 PM Marc Garcia <notifications@github.com>
wrote:

> I thought about it, but as pymysql and psycopg are not in environment.yml,
> I didn't see a difference, as the tests should be skipped anyway.
>
> Happy to change it, I don't have a preference.
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/issues/24485#issuecomment-450517431>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIrNIswmqe_-tEAL2uxwR70aJbeW5ks5u985dgaJpZM4Zkpg3>
> .
>

ok, will open a PR

Resolving patch:
diff --git a/pandas/conftest.py b/pandas/conftest.py
--- a/pandas/conftest.py
+++ b/pandas/conftest.py
@@ -1,3 +1,4 @@
+import collections
 from datetime import date, time, timedelta
 from decimal import Decimal
 import importlib
@@ -54,14 +55,22 @@ def pytest_runtest_setup(item):
     if 'network' in item.keywords and item.config.getoption("--skip-network"):
         pytest.skip("skipping due to --skip-network")
 
-    if 'db' in item.keywords and item.config.getoption("--skip-db"):
-        pytest.skip("skipping due to --skip-db")
-
     if 'high_memory' in item.keywords and not item.config.getoption(
             "--run-high-memory"):
         pytest.skip(
             "skipping high memory test since --run-high-memory was not set")
 
+    # if "db" not explicitly set in the -m pattern, we skip the db tests
+    if 'db' in item.keywords:
+        pattern = item.config.getoption('-m')
+        markers = collections.defaultdict(bool)
+        for marker in item.iter_markers():
+            markers[marker.name] = True
+        markers['db'] = False
+        db_in_pattern = not eval(pattern, {}, markers)
+        if not db_in_pattern:
+            pytest.skip('skipping db unless -m "db" is specified')
+
 
 # Configurations for all tests and all test modules
 
diff --git a/pandas/util/_tester.py b/pandas/util/_tester.py
--- a/pandas/util/_tester.py
+++ b/pandas/util/_tester.py
@@ -16,7 +16,7 @@ def test(extra_args=None):
         import hypothesis  # noqa
     except ImportError:
         raise ImportError("Need hypothesis>=3.58 to run tests")
-    cmd = ['--skip-slow', '--skip-network', '--skip-db']
+    cmd = ['--skip-slow', '--skip-network']
     if extra_args:
         if not isinstance(extra_args, list):
             extra_args = [extra_args]


Test patch: