diff --git a/CHANGES.rst b/CHANGES.rst index f183c6c1..0c2677a8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,8 @@ unreleased ---------- - [enhancement] extract NoopExecutor into it's own submodule +- [bugfix] Ignore occasional `ProcessFinishedWithError` error on executor exit. +- [bugfix] Fixed setting custom password for process fixture - [bugfix] Fix version detection, to allow for two-digit minor version part 2.4.0 diff --git a/src/pytest_postgresql/executor.py b/src/pytest_postgresql/executor.py index 72dfaaee..c736d2e5 100644 --- a/src/pytest_postgresql/executor.py +++ b/src/pytest_postgresql/executor.py @@ -27,6 +27,7 @@ from pkg_resources import parse_version from mirakuru import TCPExecutor from mirakuru.base import ExecutorType +from mirakuru.exceptions import ProcessFinishedWithError class PostgreSQLUnsupported(Exception): @@ -221,7 +222,11 @@ def stop(self, datadir=self.datadir, ), shell=True) - super().stop(sig, exp_sig) + try: + super().stop(sig, exp_sig) + except ProcessFinishedWithError: + # Finished, leftovers ought to be cleaned afterwards anyway + pass def __del__(self): """Make sure the directories are properly removed at the end.""" diff --git a/tests/test_executor.py b/tests/test_executor.py index 1459003a..f3c4c23d 100644 --- a/tests/test_executor.py +++ b/tests/test_executor.py @@ -1,7 +1,10 @@ """Test various executor behaviours.""" +import sys + +from pkg_resources import parse_version + import psycopg2 import pytest -from pkg_resources import parse_version from pytest_postgresql.executor import PostgreSQLExecutor, PostgreSQLUnsupported from pytest_postgresql.factories import postgresql_proc @@ -36,6 +39,42 @@ def test_unsupported_version(request): executor.start() +@pytest.mark.skipif( + sys.platform == "darwnin", + reason="Mac Os has completely different path for the executable" + " than linux, and the default config." +) +def test_executor_init_with_password(request): + """Test whether the executor initializes properly.""" + config = get_config(request) + executor = PostgreSQLExecutor( + executable=config['exec'], + host=config['host'], + port=get_port(config['port']), + datadir='/tmp/error', + unixsocketdir=config['unixsocketdir'], + logfile='/tmp/version.error.log', + startparams=config['startparams'], + password="somepassword", + ) + with executor: + assert executor.running() + psycopg2.connect( + dbname=executor.user, + user=executor.user, + password=executor.password, + host=executor.host, + port=executor.port) + with pytest.raises(psycopg2.OperationalError): + psycopg2.connect( + dbname=executor.user, + user=executor.user, + password='bogus', + host=executor.host, + port=executor.port) + assert not executor.running() + + postgres_with_password = postgresql_proc(password='hunter2')