Skip to content
Snippets Groups Projects
Commit eb386867 authored by David Douard's avatar David Douard
Browse files

test: actually check (and fix) tests that are expecting psql command to fail

Actually check they are failing for the expected reason. This needs to
replace usage of subprocess.check_call by subprocess.run with proper
arguments so that the stderr of the process is captured and attached to
the raised CalledProcessError exception.
parent c0164695
No related branches found
No related tags found
No related merge requests found
......@@ -706,7 +706,9 @@ def execute_sqlfiles(
flavor_set = False
for sqlfile in sqlfiles:
logger.debug(f"execute SQL file {sqlfile} dbname={conninfo}")
subprocess.check_call(psql_command + ["-f", str(sqlfile)])
subprocess.run(
psql_command + ["-f", str(sqlfile)], check=True, capture_output=True
)
if (
flavor is not None
......
......@@ -3,6 +3,7 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
from subprocess import CalledProcessError
import traceback
import pytest
......@@ -122,6 +123,8 @@ def test_cli_swh_db_initialization_fail_without_creation_first(
result = cli_runner.invoke(swhdb, ["init", module_name, "--dbname", conninfo])
# Fails because we cannot connect to an inexisting db
assert result.exit_code == 1, f"Unexpected output: {result.output}"
assert isinstance(result.exception, CalledProcessError)
assert b'FATAL: database "inexisting-db" does not exist' in result.exception.stderr
def test_cli_swh_db_initialization_fail_without_extension(
......@@ -132,13 +135,18 @@ def test_cli_swh_db_initialization_fail_without_extension(
In this test, the schema needs privileged extension to work.
"""
module_name = "test" # it's mocked here
module_name = "test.postgresql" # it's mocked here
conninfo = craft_conninfo(postgresql)
result = cli_runner.invoke(swhdb, ["init", module_name, "--dbname", conninfo])
# Fails as the function `public.digest` is not installed, init-admin calls is needed
# first (the next tests show such behavior)
assert result.exit_code == 1, f"Unexpected output: {result.output}"
assert isinstance(result.exception, CalledProcessError)
assert (
b"ERROR: function public.digest(text, unknown) does not exist"
in result.exception.stderr
)
def test_cli_swh_db_initialization_works_with_flags(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment