Skip to content

Commit

Permalink
Merge 8004414 into e0c6979
Browse files Browse the repository at this point in the history
  • Loading branch information
fizyk committed Aug 20, 2020
2 parents e0c6979 + 8004414 commit 7b75d27
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/pytest_postgresql/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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."""
Expand Down
41 changes: 40 additions & 1 deletion tests/test_executor.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')


Expand Down

0 comments on commit 7b75d27

Please sign in to comment.