From 8f8cdf81a5e111001c1cdbad987df1f38abe7b75 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 3 Oct 2023 10:38:34 -0600 Subject: [PATCH 1/2] 'PostgreSQL' object has no attribute '_conn' --- data_diff/databases/postgresql.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data_diff/databases/postgresql.py b/data_diff/databases/postgresql.py index 2b044b36..996d7a4a 100644 --- a/data_diff/databases/postgresql.py +++ b/data_diff/databases/postgresql.py @@ -147,10 +147,10 @@ def create_connection(self): pg = import_postgresql() try: - c = pg.connect(**self._args) + self._conn = pg.connect(**self._args) if SESSION_TIME_ZONE: - c.cursor().execute(f"SET TIME ZONE '{SESSION_TIME_ZONE}'") - return c + self._conn.cursor().execute(f"SET TIME ZONE '{SESSION_TIME_ZONE}'") + return self._conn except pg.OperationalError as e: raise ConnectError(*e.args) from e From 33bfbd74ac50a5e52fb0a07f78627947cfadbfda Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 3 Oct 2023 11:26:12 -0600 Subject: [PATCH 2/2] raise without --debug, expand cli test --- data_diff/__main__.py | 3 +-- tests/test_cli.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/data_diff/__main__.py b/data_diff/__main__.py index ba006d36..016f3d7d 100644 --- a/data_diff/__main__.py +++ b/data_diff/__main__.py @@ -327,8 +327,7 @@ def main(conf, run, **kw): ) except Exception as e: logging.error(e) - if kw["debug"]: - raise + raise def _data_diff( diff --git a/tests/test_cli.py b/tests/test_cli.py index 1fc4833e..9dfd97c4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -11,12 +11,17 @@ def run_datadiff_cli(*args): try: - stdout = subprocess.check_output( - [sys.executable, "-m", "data_diff", "--no-tracking"] + list(args), stderr=subprocess.PIPE + p = subprocess.Popen( + [sys.executable, "-m", "data_diff", "--no-tracking"] + list(args), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, ) + stdout, stderr = p.communicate() except subprocess.CalledProcessError as e: logging.error(e.stderr) raise + if stderr: + raise Exception(stderr) return stdout.splitlines() @@ -48,6 +53,7 @@ def setUp(self) -> None: def test_basic(self): conn_str = CONN_STRINGS[self.db_cls] diff = run_datadiff_cli(conn_str, self.table_src_name, conn_str, self.table_dst_name) + assert len(diff) == 1 def test_options(self):