summaryrefslogtreecommitdiffstats
path: root/tests/features/environment.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-09-20 15:46:57 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-09-20 15:46:57 +0000
commit917739023a7acaae3645bbfd27ed454df3c5be33 (patch)
tree4e205849ae64ccd4d1797a1ad7579416f69f52ee /tests/features/environment.py
parentAdding upstream version 3.4.1. (diff)
downloadpgcli-917739023a7acaae3645bbfd27ed454df3c5be33.tar.xz
pgcli-917739023a7acaae3645bbfd27ed454df3c5be33.zip
Adding upstream version 3.5.0.upstream/3.5.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/features/environment.py')
-rw-r--r--tests/features/environment.py36
1 files changed, 28 insertions, 8 deletions
diff --git a/tests/features/environment.py b/tests/features/environment.py
index 215c85c..6cc8e14 100644
--- a/tests/features/environment.py
+++ b/tests/features/environment.py
@@ -111,7 +111,11 @@ def before_all(context):
context.conf["dbname"],
context.conf["port"],
)
-
+ context.pgbouncer_available = dbutils.pgbouncer_available(
+ hostname=context.conf["host"],
+ password=context.conf["pass"],
+ username=context.conf["user"],
+ )
context.fixture_data = fixutils.read_fixture_files()
# use temporary directory as config home
@@ -145,7 +149,7 @@ def after_all(context):
context.conf["port"],
)
- # Remove temp config direcotry
+ # Remove temp config directory
shutil.rmtree(context.env_config_home)
# Restore env vars.
@@ -164,7 +168,19 @@ def before_scenario(context, scenario):
if scenario.name == "list databases":
# not using the cli for that
return
- wrappers.run_cli(context)
+ currentdb = None
+ if "pgbouncer" in scenario.feature.tags:
+ if context.pgbouncer_available:
+ os.environ["PGDATABASE"] = "pgbouncer"
+ os.environ["PGPORT"] = "6432"
+ currentdb = "pgbouncer"
+ else:
+ scenario.skip()
+ else:
+ # set env vars back to normal test database
+ os.environ["PGDATABASE"] = context.conf["dbname"]
+ os.environ["PGPORT"] = context.conf["port"]
+ wrappers.run_cli(context, currentdb=currentdb)
wrappers.wait_prompt(context)
@@ -172,13 +188,17 @@ def after_scenario(context, scenario):
"""Cleans up after each scenario completes."""
if hasattr(context, "cli") and context.cli and not context.exit_sent:
# Quit nicely.
- if not context.atprompt:
+ if not getattr(context, "atprompt", False):
dbname = context.currentdb
- context.cli.expect_exact(f"{dbname}> ", timeout=15)
- context.cli.sendcontrol("c")
- context.cli.sendcontrol("d")
+ context.cli.expect_exact(f"{dbname}>", timeout=5)
+ try:
+ context.cli.sendcontrol("c")
+ context.cli.sendcontrol("d")
+ except Exception as x:
+ print("Failed cleanup after scenario:")
+ print(x)
try:
- context.cli.expect_exact(pexpect.EOF, timeout=15)
+ context.cli.expect_exact(pexpect.EOF, timeout=5)
except pexpect.TIMEOUT:
print(f"--- after_scenario {scenario.name}: kill cli")
context.cli.kill(signal.SIGKILL)