diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-06-09 10:59:23 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-06-09 11:59:22 -0400 |
| commit | b0bf421f1b12eeedd77ec6c39df8e5e6cc1fcc3f (patch) | |
| tree | 8905048db510986642f7978192751f3d471661ad /test | |
| parent | e2521b595ae8b5b4ca8147c5ee13e2fc0f597e63 (diff) | |
| download | sqlalchemy-b0bf421f1b12eeedd77ec6c39df8e5e6cc1fcc3f.tar.gz | |
psycopg2 NOTICE fixup
- don't call relatively expensive isEnabledFor(), just call _log_notices
- don't reset the list if it's empty
- fix the test to use a custom function to definitely create a notice, confirmed
that PG seems to no longer create the "implicit sequence" notices
- assert that the reset of the notices works too
- update the docs to illustrate for folks who haven't worked with logging before
Change-Id: I7291e647c177d338e0ad673f3106b4d503e4b3ea
Diffstat (limited to 'test')
| -rw-r--r-- | test/dialect/postgresql/test_dialect.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py index 25cba6269..0bbfe50fb 100644 --- a/test/dialect/postgresql/test_dialect.py +++ b/test/dialect/postgresql/test_dialect.py @@ -39,6 +39,7 @@ from sqlalchemy.testing.assertions import assert_raises_message from sqlalchemy.testing.assertions import AssertsCompiledSQL from sqlalchemy.testing.assertions import AssertsExecutionResults from sqlalchemy.testing.assertions import eq_ +from sqlalchemy.testing.assertions import eq_regex from sqlalchemy.testing.assertions import ne_ from sqlalchemy.testing.mock import Mock from ...engine import test_execute @@ -267,11 +268,9 @@ class MiscBackendTest( ) assert isinstance(exception, exc.OperationalError) - # currently not passing with pg 9.3 that does not seem to generate - # any notices here, would rather find a way to mock this @testing.requires.no_coverage @testing.requires.psycopg2_compatibility - def _test_notice_logging(self): + def test_notice_logging(self): log = logging.getLogger("sqlalchemy.dialects.postgresql") buf = logging.handlers.BufferingHandler(100) lev = log.level @@ -281,15 +280,29 @@ class MiscBackendTest( conn = testing.db.connect() trans = conn.begin() try: - conn.execute("create table foo (id serial primary key)") + conn.execute( + """ +CREATE OR REPLACE FUNCTION note(message varchar) RETURNS integer AS $$ +BEGIN + RAISE NOTICE 'notice: %%', message; + RETURN NULL; +END; +$$ LANGUAGE plpgsql; +""" + ) + conn.execute("SELECT note('hi there')") + conn.execute("SELECT note('another note')") finally: trans.rollback() finally: log.removeHandler(buf) log.setLevel(lev) msgs = " ".join(b.msg for b in buf.buffer) - assert "will create implicit sequence" in msgs - assert "will create implicit index" in msgs + eq_regex( + msgs, + "NOTICE: notice: hi there(\nCONTEXT: .*?)? " + "NOTICE: notice: another note(\nCONTEXT: .*?)?", + ) @testing.requires.psycopg2_or_pg8000_compatibility @engines.close_open_connections |
